需要帮助来解析Java中的JSON

时间:2019-05-08 14:53:37

标签: java

我正在尝试从JSON中的GET请求中读取错误结果

我必须像这样读取commes的JSON:

{
  "dictionary": {
    "id": "chiffreAffaires",
    "entries": {
      "QmV23fHBLwTh99Na1p5ifHmcsuo9qgChGMwzx4eeabAjKx": {
        "tags": "||1999||",
        "value": "1",
        "author": "santos.bruno1203@gmail.com",
        "date": "201905081232",
        "previous": null,
        "conf": []

我已经尝试过了:

String myURL = "...";
URL url = new URL(myURL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();

// optional default is GET
con.setRequestMethod("GET");


BufferedReader in = new BufferedReader(
        new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response);
JSONObject obj = new JSONObject(response);
JSONArray arr = obj.getJSONArray("entries");
for (int i = 0; i < arr.length(); i++) {
    String tags = arr.getJSONObject(i).getString("tags");
    System.out.println(tags);
}

我遇到一条错误消息:线程“ AWT-EventQueue-0” org.json.JSONException中的异常:找不到JSONObject [“ entries”]。

我不知道为什么会出现这个错误

0 个答案:

没有答案