- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个简单的 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/
我编写了一个 REST 服务来从发布请求中提取元数据。我正在使用 spring-data-elasticsearch,并且我制作了一个自定义元数据对象来将 Json 反序列化为如下所示: @Docum
我正在尝试用 Java 语言和 Netbeans(作为 IDE)构建一个天气应用程序。代码如下: URL link = new URL("http://api.dataweave.in/v1/weat
我在按索引访问字段时遇到问题。这个图书馆https://github.com/buger/jsonparser 示例来自 https://github.com/buger/jsonparser : /
我正在使用 org.json.simple.parser JSON 解析器。一项具体数据包含着非常大的数字。例如,在解析带有此错误的行时曾经失败 java.lang.NumberFormatExcep
我正在使用 GSON 库通过从变量中获取输入来生成 json 对象,并且 json 对象还包含数组,它是字符串类型。 我尝试了以下方法: import java.io.BufferedReader;
每次我添加 compile com.googlecode.json-simple:json-simple:1.1.1 以使用 JSONParse 和其他内容时,我的应用将无法构建或运行,并且会显示以下
我正在使用 selenium webdriver,我创建了一个 JSON 文件,但是当我使用 JSONParser 从该文件读取数据时,Eclipse 显示错误“JSONParser 无法解析为类型”
获取 Spring Boot 应用程序的 JsonParser 已弃用的消息, JsonObject jsonObject = new JsonParser().parse(result).getAs
我正在做一个项目,它应该从 JSON 文件中提取数据(包含有关波兰代表的信息),并仅使用这些数据进行一些计算。 代码执行正常,但有一种方法会大大降低一切速度。 我不是最擅长描述的,所以让我们展示一下我
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在遍历 Json 文件,似乎只得到空值。正如你所看到的,我正在尝试使用索引来访问它们。另外,我的整数很有趣,因为它不喜欢我使用 json 值中的 Integer.parseInt 。 JSON:
我在一个项目中工作,我需要其中的资源。我正在尝试使用此代码获取它: InputStream is =JSONParser.class.getResourceAsStream("a.json"); St
尝试在网络上部署我的第一个 libgdx 游戏并运行命令./gradlew html:dist 在 android studio 终端中,但我不断收到以下错误 [ERROR] Line 51: No
我有一个 Date 序列化器,在反序列化 Date 对象时会添加时区,但我注意到一些 Date 对象被转换为 String,而不是长值,而是得到 Date 的 String 值。 所以当我尝试: Lo
所以我导入了 import org.json.* 并且它似乎无法识别 JSONParser。 String filePath = "C://CN//jokes.json"; try {
尝试遵循本教程:Tutorial 尝试像这样使用 JSONParser: // Creating JSON Parser object JSONParser jParser = new JSONPar
我发现 JsonParser 在 javax.json.stream 中,但我不知道在哪里可以找到它。谁能帮帮我? https://docs.oracle.com/javaee/7/api/javax
我的代码是: var json = $.parseJSON(data); CKEDITOR.instances.post_editor.setData(json.content); $("#postT
我想验证传入的 JSON,目前该方法未解析 JSON,错误的 json 将继续破坏所有内容,我想安全漏洞也可以构建到错误的 JSON 字符串中。 JsonParser parser = new Jso
我在这里完全空白 - 在 gson 中解析时没有方便的方法来处理空格?我遇到以下异常: com.google.gson.JsonSyntaxException: com.google.gson.str
我是一名优秀的程序员,十分优秀!