gpt4 book ai didi

java - 如何在gwt中使用clientbundle使用JSON文件

转载 作者:太空宇宙 更新时间:2023-11-04 13:43:51 25 4
gpt4 key购买 nike

我有一个静态 JSON 文件,我想在我的 GWT 代码中访问它。 custom-report.json 文件位于项目的 client 包中。我将其添加到 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 文件的正确方法。

最佳答案

您需要使用 GWT 提供的 com.google.gwt.json.client.JSONParser 而不是 org.json.simple.parser.JSONParser

JSONValue value = JSONParser.parse(json);
JSONObject productsObj = value.isObject();
JSONArray productsArray = productsObj.get("products").isArray();

关于java - 如何在gwt中使用clientbundle使用JSON文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31055097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com