gpt4 book ai didi

java - 在 GWT 中使用 JSONParser 的问题

转载 作者:搜寻专家 更新时间:2023-10-31 08:11:55 25 4
gpt4 key购买 nike

我有一个简单的 GWT 应用程序,需要从另一台服务器获取一些 JSON 数据。我已经遵循了几个教程来达到这一点。当我尝试编译它时,出现错误

[ERROR] Line 44: No source code is available for type com.google.gwt.json.client.JSONValue; did you forget to inherit a required module? [ERROR] Line 44: No source code is available for type com.google.gwt.json.client.JSONParser; did you forget to inherit a required module? [ERROR] Line 46: No source code is available for type com.google.gwt.json.client.JSONArray; did you forget to inherit a required module? [ERROR] Line 49: No source code is available for type com.google.gwt.json.client.JSONObject; did you forget to inherit a required module?

我知道我必须添加

<inherits name="com.google.gwt.http.HTTP" />

添加到我的 .gwt.xml 文件,但无法弄清楚要添加什么来让它识别 JSON 内容。请问我错过了什么?

相关代码:

  private SearchResult[] parseResponse(String jsonResponse) {
ArrayList<SearchResult> retArray = new ArrayList<SearchResult>();

JSONValue jval = JSONParser.parseStrict(jsonResponse);

JSONArray resultArray = jval.isArray();

for(int i=0; i<resultArray.size(); i++) {
JSONObject resultObj = resultArray.get(i).isObject();
String title = resultObj.get("title").isString().stringValue();
JSONArray roleArray = resultObj.get("roles").isArray();
String roleNames = new String();
for(int j=0; j< roleArray.size(); j++) {
if(roleArray.get(j).isNumber().doubleValue() == 1.0) {
// this role is present
String currRole = Constants.getRoleNameForNum(j);
roleNames += currRole;
}
}
SearchResult sr = new SearchResult(title, roleNames);
retArray.add(sr);
}

return retArray.toArray(new SearchResult[0]);
}

private void doSearch() {

clearTable();

final String searchTerms = searchTextBox.getText().toLowerCase().trim();
searchTextBox.setFocus(true);
final int roleNum = roleChooserBox.getSelectedIndex();
final String roleName = roleChooserBox.getItemText(roleNum);
String url = JSON_URL + "?" + ROLE_TXT + roleNum + "&" + QUERY_TXT + "'" + searchTerms + "'";
url = URL.encode(url);

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
try {
Request request = builder.sendRequest(null, new RequestCallback() {

@Override
public void onError(Request request, Throwable exception) {
displayError("Couldnt' retrieve JSON");

}
@Override
public void onResponseReceived(Request request, Response response) {


if (200 == response.getStatusCode()) {
SearchResult[] results = parseResponse(response.getText());
updateTable(results, roleName);
} else {
displayError("Couldn't retrieve JSON (" + response.getStatusText()
+ ")");
}
}
});
} catch (RequestException e) {
displayError("Couldn't retrieve JSON");
}
`

最佳答案

经过进一步的尝试和错误,添加

<inherits name="com.google.gwt.json.JSON" />

我的 .gwt.xml 文件成功了。我很失望在文档中找不到任何信息来解释这一点。这会节省很多时间。

关于java - 在 GWT 中使用 JSONParser 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28442636/

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