在GWT(JSNI)中将字符串转换为JSON对象

3
如何将字符串转换为JSON对象以在JSNI中使用? 谢谢。
2个回答

4
这是一种复制粘贴的方法:
import com.google.gwt.core.client.JsonUtils;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;

...

JSONObject data = new JSONObject(JsonUtils.safeEval(jsonString));
JSONArray array = data.get("anArray").isArray();
JSONObject obj = data.get("anObject").isObject();

1
你应该查看gwt core JsonUtils,它有一个安全的字符串解析方法。你应该定义一个JavaScript Overlay Object来使用结果,或者你可以像你想要的那样在JSNI中处理该对象。

谢谢!我使用 JSNI 中的 JSON.parse() 解决了这个问题。 - Abdessamad Doughri

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接