org.json.JSON.typeMismatch(JSON.java:100) 处出错

Error at org.json.JSON.typeMismatch(JSON.java:100)

实际上我正在尝试从 YQL 检索数据,我在这方面取得了一定的成功,但是当它变得复杂时 json objects/arrays,调试器向我显示了这个错误

at org.json.JSON.typeMismatch(JSON.java:100)

Link for JSON incase if live match is not going on this is the JSON code

{
 "query": {
  "count": 1,
  "created": "2017-04-07T20:16:20Z",
  "lang": "en-US",
  "diagnostics": {
   "cache": {
    "execution-start-time": "0",
    "execution-stop-time": "2",
    "execution-time": "2",
    "method": "GET",
    "type": "MEMCACHED",
    "content": "TABLE.queryyahooapiscomproductionsg3.cricket.scorecard.live.summary.4daacfcfafc467783e90b0c5c31a615f"
   },
   "publiclyCallable": "true",
   "url": {
    "execution-start-time": "2",
    "execution-stop-time": "5",
    "execution-time": "3",
    "content": "http://cricketwebservice/ws/cwsapi/live/livematches.php?output=summary"
   },
   "user-time": "5",
   "service-time": "5",
   "build-version": "2.0.97"
  },
  "results": {
   "Scorecard": {
    "v": "0",
    "mid": "196000",
    "m": "2",
    "series": {
     "series_id": "12604",
     "series_name": "Pakistan in West Indies ODI Series, 3 ODI Cricket Series, 2017"
    },
    "ecf": "0",
    "place": {
     "vid": "179",
     "stadium": "Providence Stadium, Guyana",
     "city": "Guyana",
     "country": "West Indies",
     "Gimaget": "https://s.yimg.com/qx/cricket/fufp/images/venue_179_thumb-12-7-2010-89c7b8de5692a58c7abcd56bd61fdfeb.jpg",
     "date": "20170407133000",
     "enddate": "20170407213000"
    },
    "mn": "1st ODI",
    "teams": [
     {
      "i": "9",
      "fn": "West Indies",
      "sn": "WI",
      "logo": {
       "std": "https://s.yimg.com/qx/cricket/fufp/images/west_indies-26-2-2013-d3ee3026b84398864c10e4320494c6e8.jpg",
       "small": "https://s.yimg.com/qx/cricket/fufp/images/west_indies_small-26-2-2013-d0e88ec3179f31a2c0ebc05e1830453e.jpg"
      },
      "flag": {
       "std": "https://s.yimg.com/qx/cricket/fufp/images/west_indies_flag-1-2-2011-1f60ba1dc32a680e11ae5efe99bcc924.gif",
       "small": "https://s.yimg.com/qx/cricket/fufp/images/west_indies_flag_small-1-2-2011-7f81c93235b1ea332d460c28778e21a4.gif",
       "roundstd": "https://s.yimg.com/qx/cricket/fufp/images/9-11-2-2012-c51c1d9604f42152a6e87e5cb38542e3.png",
       "roundsmall": "https://s.yimg.com/qx/cricket/fufp/images/9_s-11-2-2012-b317c02e8201f9cbbefd3d21381bb534.png",
       "roundlarge": "https://s.yimg.com/qx/cricket/fufp/images/9_l-11-2-2012-da7e8c6fe82f0fa6ec7ee4d3051d3ba6.png"
      }
     },
     {
      "i": "6",
      "fn": "Pakistan",
      "sn": "PAK",
      "logo": {
       "std": "https://s.yimg.com/qx/cricket/fufp/images/pakistan-26-2-2013-f6f54d67dea9677b03ddc1c009c070f9.jpg",
       "small": "https://s.yimg.com/qx/cricket/fufp/images/pakistan_small-26-2-2013-6af95f1da13f29b8ef5ccfbf3cb89648.jpg"
      },
      "flag": {
       "std": "https://s.yimg.com/qx/cricket/fufp/images/pakistan_flag-1-2-2011-f99a8132f62ed22d64b985c2ba0d65eb.gif",
       "small": "https://s.yimg.com/qx/cricket/fufp/images/pakistan_flag_small-1-2-2011-5bbc7ebe24b9bc2460e131bfc9cafd78.gif",
       "roundstd": "https://s.yimg.com/qx/cricket/fufp/images/6-11-2-2012-e492bb0be566324796f25d3bcd2c3019.png",
       "roundsmall": "https://s.yimg.com/qx/cricket/fufp/images/6_s-11-2-2012-2ef4be67daf68f843f48115ff5ba8f1a.png",
       "roundlarge": "https://s.yimg.com/qx/cricket/fufp/images/6_l-11-2-2012-472fc93551b80e5564b9fd0355191a4e.png"
      }
     }
    ],
    "past_ings": [
     {
      "s": {
       "t": "1",
       "i": "2",
       "ps": "0",
       "stay_live": "Yes",
       "ld": "No",
       "ldmsg": null,
       "pms": "live",
       "ed": "Power Play 2",
       "a": {
        "fo": "0",
        "pp": "2",
        "i": "9",
        "cr": "4.69",
        "r": "158",
        "o": "33.4",
        "w": "4",
        "b": "0",
        "lb": "5",
        "wd": "12",
        "nb": "1",
        "pt": "0",
        "l": "0",
        "rr": "9.24",
        "ru": "151",
        "ro": "16.2",
        "tg": "309",
        "cp": {
         "cp": "2",
         "bls": "9",
         "s": "1"
        }
       },
       "tz": "-04:00"
      },
      "d": {
       "a": {
        "t": {
         "i": "11705",
         "a": "3",
         "c": "Batting",
         "dt": null,
         "fd": "0",
         "bd": "0",
         "cb": "no",
         "b": "4",
         "r": "1",
         "sr": "25",
         "four": "0",
         "six": "0",
         "name": "Jason Mohammed"
        }
       }
      }
     },
     {
      "s": {
       "t": "1",
       "i": "1",
       "ps": "0",
       "stay_live": "Yes",
       "ld": "No",
       "ldmsg": null,
       "pms": "live",
       "ed": "Power Play 3",
       "a": {
        "fo": "0",
        "pp": "3",
        "i": "6",
        "cr": "6.16",
        "r": "308",
        "o": "50",
        "w": "5",
        "b": "3",
        "lb": "3",
        "wd": "7",
        "nb": "1",
        "pt": "0",
        "l": "0"
       },
       "tz": "-04:00"
      }
     }
    ],
    "toss": {
     "win": "9",
     "bat": "0",
     "text": "xxx-xxx-xxx"
    },
    "result": "0",
    "ms": "Drinks",
    "mt": "2",
    "cts": "1491596158"
   }
  }
 }
}

下面是我到目前为止尝试过的代码。

try {
            JSONObject jsonObject = new JSONObject(response);

            JSONObject query = jsonObject.getJSONObject("query");
            JSONObject results = query.getJSONObject("results");
            JSONArray Scorecard = results.getJSONArray("Scorecard");
            for (int i = 0; i < Scorecard.length(); i++) {

                JSONObject e = Scorecard.getJSONObject(i);
                JSONArray past_ings = new JSONArray(e.getString("past_ings"));

                for (int j = 0; j < past_ings.length(); j++) {

                    JSONObject f = past_ings.getJSONObject(j);
                    JSONObject getter = new JSONObject(f.getString("s"));

                    team = getter.getString("t");

                }
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

但现在我想访问 "s"

中的 "a" 对象

所以我哪里做错了?

PS:以上代码有效。

首先记分卡不是数组。我更改了您的代码并使用您的 JSON 进行了测试。有效。

try {
        JSONObject jsonObject = new JSONObject(json);

        JSONObject query = jsonObject.getJSONObject("query");
        JSONObject results = query.getJSONObject("results");
        JSONObject Scorecard = results.getJSONObject("Scorecard");

        JSONArray past_ings = Scorecard.getJSONArray("past_ings");

        for (int j = 0; j < past_ings.length(); j++) {

            JSONObject f = past_ings.getJSONObject(j);
            JSONObject getter = new JSONObject(f.getString("s"));

            JSONObject a = getter.getJSONObject("a");

        }


    } catch (JSONException e) {
        e.printStackTrace();
    }