我有一个静态JSON文件,我想在我的GWT代码中访问它。定制的report.json文件位于项目的客户端包中。我正在ClientBundle中添加它并试图访问它,但是我得到了一个错误
public interface AppBundle extends ClientBundle {
@Source("custom-report.json")
public TextResource jsonData();
public static final AppBundle INSTANCE = GWT.create(AppBundle.class);
}要在我的代码中使用它,我要做的是:
AppBundle.INSTANCE.mystyle().ensureInjected();
JSONObject obj = (JSONObject) parser.parse(new FileReader(AppBundle.INSTANCE.jsonData().getText()));这给了我编译错误。
[ERROR] Line 29: No source code is available for type org.json.simple.parser.JSONParser; did you forget to inherit a required module?我不确定这是否是在GWT中使用JSON文件的正确方式。
发布于 2015-06-27 08:18:13
您需要使用由com.google.gwt.json.client.JSONParser而不是org.json.simple.parser.JSONParser提供的org.json.simple.parser.JSONParser。
JSONValue value = JSONParser.parse(json);
JSONObject productsObj = value.isObject();
JSONArray productsArray = productsObj.get("products").isArray();https://stackoverflow.com/questions/31055097
复制相似问题