我使用amirdew/JSON库,你可以在这里找到将我的字符串解析为JSON。我检索到的字符串如下:https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=Portugal
这是我目前的代码,它不起作用,我相信这是因为钥匙.
public void ParseJson (String json){
JSON json2 = new JSON(json);
String firstTag = json2.key("query").key("pages").key("extract").stringValue();
txtInfo = findViewById(R.id.txtInfo);
txtInfo.setText(firstTag);
}firstTag变量为null,因为它不能检索任何值。我想检索"extracts“中的文本。我该怎么做呢?我需要什么钥匙?
发布于 2018-07-03 15:15:27
我建议您使用已经在JSONObject中的SDK。你会像这样使用它:
String input = "..."; // your input
JSONObject obj = new JSONObject(input);
Strings extracts = obj.getJSONObject("query").getJSONObject("pages").getJSONObject("23033").getString("extract");https://stackoverflow.com/questions/51157836
复制相似问题