我正在尝试读取此JSON并获取每个键的值。 URL中的JSON看起来像这样。
{"gameList":[{"gameId":2889909885,"mapId":12,"gameMode":"ARAM","gameType":"MATCHED_GAME","gameQueueConfigId":450,"participants":[{"teamId":100,"spell1Id":4,"spell2Id":14,"championId":103,"profileIconId":1665,"summonerName":"suprise motherfk","bot":false},{"teamId":100,"spell1Id":32,"spell2Id":14,"championId":111,"profileIconId":539,"summonerName":"Celebi Master","bot":false},{"teamId":100,"spell1Id":4,"spell2Id":7,"championId":163,"profileIconId":577,"summonerName":"Sontz","bot":false},{"teamId":100,"spell1Id":4,"spell2Id":32,"championId":59,"profileIconId":3566,"summonerName":"Milhao","bot":false},{"teamId":100,"spell1Id":3,"spell2Id":4,"championId":202,"profileIconId":3764,"summonerName":"Fistacles","bot":false},{"teamId":200,"spell1Id":32,"spell2Id":4,"championId":154,"profileIconId":539,"summonerName":"Dante Highwind","bot":false},{"teamId":200,"spell1Id":4,"spell2Id":7,"championId":134,"profileIconId":3587,"summonerName":"Get Derived","bot":false},{"teamId":200,"spell1Id":32,"spell2Id":4,"championId":14,"profileIconId":3715,"summonerName":"Hestory","bot":false},{"teamId":200,"spell1Id":4,"spell2Id":7,"championId":126,"profileIconId":3541,"summonerName":"Jayjang","bot":false},{"teamId":200,"spell1Id":14,"spell2Id":4,"championId":157,"profileIconId":578,"summonerName":"Kledy McKledFace","bot":false}],"observers":{"encryptionKey":"nRC9PwcmfeYTQg6F2cWjE0//wCgOI40z"},"platformId":"NA1","bannedChampions":[],"gameStartTime":1539909193767,"gameLength":46},{"gameId":2889900079,"mapId":12,"gameMode":"ARAM","gameType":"MATCHED_GAME","gameQueueConfigId":450,"participants":[{"teamId":100,"spell1Id":4,"spell2Id":32,"championId":266,"profileIconId":3186,"summonerName":"meScott","bot":false},{"teamId":100,"spell1Id":32,"spell2Id":4,"championId":12,"profileIconId":3552,"summonerName":"chogs08","bot":false},{"teamId":100,"spell1Id":21,"spell2Id":4,"championId":67,"profileIconId":3551,"summonerName":"Constantinople","bot":false},{"teamId":100,"spell1Id":7,"spell2Id":4,"championId":96,"profileIconId":3717,"summonerName":"tanjo3","bot":false},{"teamId":100,"spell1Id":3,"spell2Id":4,"championId":84,"profileIconId":3632,"summonerName":"xR4YZ0Rx","bot":false},{"teamId":200,"spell1Id":4,"spell2Id":32,"championId":3,"profileIconId":3102,"summonerName":"RAT IG","bot":false},{"teamId":200,"spell1Id":4,"spell2Id":32,"championId":76,"profileIconId":3614,"summonerName":"IM ALIVE OH YEAH","bot":false},{"teamId":200,"spell1Id":4,"spell2Id":3,"championId":26,"profileIconId":3587,"summonerName":"donuts please","bot":false},{"teamId":200,"spell1Id":21,"spell2Id":4,"championId":38,"profileIconId":3778,"summonerName":"Smelloscope","bot":false},{"teamId":200,"spell1Id":21,"spell2Id":4,"championId":15,"profileIconId":3379,"summonerName":"xDingwithsalad","bot":false}],"observers":{"encryptionKey":"XaGeGBdnfK5MrJpZLDwYpptCBRvD1uwD"},"platformId":"NA1","bannedChampions":[],"gameStartTime":1539908957553,"gameLength":282},{"gameId":2889909927,"mapId":12,"gameMode":"ARAM","gameType":"MATCHED_GAME","gameQueueConfigId":450,"participants":[{"teamId":100,"spell1Id":32,"spell2Id":4,"championId":9,"profileIconId":3614,"summonerName":"Trickster Canvas","bot":false},{"teamId":100,"spell1Id":14,"spell2Id":4,"championId":64,"profileIconId":3009,"summonerName":"Fernue","bot":false},{"teamId":100,"spell1Id":7,"spell2Id":4,"championId":432,"profileIconId":3781,"summonerName":"Jack Daniels","bot":false},{"teamId":100,"spell1Id":32,"spell2Id":4,"championId":41,"profileIconId":940,"summonerName":"SwoopDogg","bot":false},{"teamId":100,"spell1Id":32,"spell2Id":4,"championId":30,"profileIconId":3440,"summonerName":"Valeth","bot":false},{"teamId":200,"spell1Id":21,"spell2Id":4,"championId":142,"profileIconId":3355,"summonerName":"MaxtheShady","bot":false},{"teamId":200,"spell1Id":21,"spell2Id":4,"championId":99,"profileIconId":745,"summonerName":"FEARedound","bot":false},{"teamId":200,"spell1Id":4,"spell2Id":7,"championId":101,"profileIconId":3072,"summonerName":"Tataki","bot":false},{"teamId":200,"spell1Id":4,"spell2Id":6,"championId":21,"profileIconId":3776,"summonerName":"IED Enilex","bot":false},{"teamId":200,"spell1Id":32,"spell2Id":4,"championId":412,"profileIconId":3147,"summonerName":"Juvia is Life","bot":false}],"observers":{"encryptionKey":"CF6RMjlV2JHR3LHwARX314ZgrShLaOGB"},"platformId":"NA1","bannedChampions":[],"gameStartTime":1539909218114,"gameLength":21},{"gameId":2889897590,"mapId":12,"gameMode":"ARAM","gameType":"MATCHED_GAME","gameQueueConfigId":450,"participants":[{"teamId":100,"spell1Id":4,"spell2Id":13,"championId":16,"profileIconId":603,"summonerName":"Lionhead","bot":false},{"teamId":100,"spell1Id":32,"spell2Id":4,"championId":12,"profileIconId":607,"summonerName":"Habebe","bot":false},{"teamId":100,"spell1Id":4,"spell2Id":7,"championId":13,"profileIconId":3461,"summonerName":"MathiasBlint","bot":false},{"teamId":100,"spell1Id":32,"spell2Id":4,"championId":22,"profileIconId":3156,"summonerName":"Old Dirty Juice","bot":false},{"teamId":100,"spell1Id":4,"spell2Id":3,"championId":74,"profileIconId":3167,"summonerName":"Hamo Hamo","bot":false},{"teamId":200,"spell1Id":7,"spell2Id":4,"championId":161,"profileIconId":931,"summonerName":"AD Paul","bot":false},{"teamId":200,"spell1Id":4,"spell2Id":13,"championId":31,"profileIconId":508,"summonerName":"LuckyClicker","bot":false},{"teamId":200,"spell1Id":4,"spell2Id":32,"championId":86,"profileIconId":691,"summonerName":"Charge Runner","bot":false},{"teamId":200,"spell1Id":32,"spell2Id":4,"championId":24,"profileIconId":3762,"summonerName":"Cutest Timo NA","bot":false},{"teamId":200,"spell1Id":4,"spell2Id":7,"championId":67,"profileIconId":3232,"summonerName":"Hoiyuen","bot":false}],"observers":{"encryptionKey":"oDkdEttv1Egnm+l4O9FiT7E9wA9XfgoH"},"platformId":"NA1","bannedChampions":[],"gameStartTime":1539909116804,"gameLength":123},{"gameId":2889889051,"mapId":12,"gameMode":"ARAM","gameType":"MATCHED_GAME","gameQueueConfigId":450,"participants":[{"teamId":100,"spell1Id":4,"spell2Id":13,"championId":202,"profileIconId":523,"summonerName":"16500211","bot":false},{"teamId":100,"spell1Id":4,"spell2Id":21,"championId":115,"profileIconId":3366,"summonerName":"FIippers","bot":false},{"teamId":100,"spell1Id":32,"spell2Id":4,"championId":72,"profileIconId":1298,"summonerName":"PaaTy","bot":false},{"teamId":100,"spell1Id":4,"spell2Id":3,"championId":74,"profileIconId":691,"summonerName":"TSOL SI EMAG EHT","bot":false},{"teamId":100,"spell1Id":4,"spell2Id":32,"championId":44,"profileIconId":3373,"summonerName":"Darkned","bot":false},{"teamId":200,"spell1Id":32,"spell2Id":4,"championId":41,"profileIconId":3499,"summonerName":"jugulaur","bot":false},{"teamId":200,"spell1Id":7,"spell2Id":4,"championId":67,"profileIconId":3777,"summonerName":"Kàrmy","bot":false},{"teamId":200,"spell1Id":13,"spell2Id":4,"championId":45,"profileIconId":3621,"summonerName":"Blunt Hits","bot":false},{"teamId":200,"spell1Id":7,"spell2Id":4,"championId":104,"profileIconId":786,"summonerName":"Buzz","bot":false},{"teamId":200,"spell1Id":7,"spell2Id":4,"championId":43,"profileIconId":1665,"summonerName":"PanPanMJ","bot":false}],"observers":{"encryptionKey":"nq3p1TBm9GLexdtxQcx9Dw522mfISRu2"},"platformId":"NA1","bannedChampions":[],"gameStartTime":1539908962887,"gameLength":276}],"clientRefreshInterval":300}
这是非常大的一行,因此为了便于查看,此处显示的是它在浏览器中的外观图像。
使用
System.out.println(json.get("gameList"));
计算之后的所有结果
{"gameList":[{
我想做的是知道如何选择其中的单个键。例如,如果我想要gameId或让我们说说其中一个游戏的summonerName。如果我想要召唤者“ surfrise motherfk”,我该如何从JSON找他。
对不起,如果这是一个简单的问题,我无法解决。
答案 0 :(得分:0)
这是我映射JSON响应的方式
String result = getJsonResponse();
try {
JSONArray jsonResponse = new JSONArray(result);
// Step through each of the Items returned
for (int i = 0; i <jsonResponse.length(); i++)
{
JSONObject jsonItem = jsonResponse.getJSONObject(i);
Item item = new Item();
item .setIndex(jsonItem.getInt("Index"));
item .setName(jsonItem.getString("Name"));
item .setActive(jsonItem.getBoolean("Active"));
item .setExists(jsonItem.getBoolean("Exists"));
item .setShouldExecuteSchedule(jsonItem.getBoolean("Execute"));
hardware.getItems().add(item);
}
} catch (JSONException e) {
e.printStackTrace();
passed = false;
}