我試圖從地圖獲取特定值。如何抓取內部的JSON地圖
我需要分配給 「leaguePoints」, 「層」, 「等級」 值, 「queueType」: 「RANKED_SOLO_5x5」 & & 「playerOrTeamName」: 「Invicterr」。
我在下面嘗試添加代碼。
我想我需要迭代條目:[],但我不知道如何去做到這一點。 我一共是JSON新手,和Java begginer。
地圖:
"32303008": {
"queue": "RANKED_SOLO_5x5",
"name": "Sejuani's Berserkers",
"entries": [
{
"isHotStreak": false,
"isFreshBlood": false,
"leagueName": "Sejuani's Berserkers",
"miniSeries": {
"progress": "LWN",
"target": 2,
"losses": 1,
"timeLeftToPlayMillis": 0,
"wins": 1
},
"isVeteran": false,
"tier": "PLATINUM",
"lastPlayed": 0,
"playerOrTeamId": "21747474",
"leaguePoints": 100,
"rank": "V",
"isInactive": false,
"queueType": "RANKED_SOLO_5x5",
"playerOrTeamName": "sunchasee",
"wins": 127
},
{
"isHotStreak": false,
"isFreshBlood": false,
"leagueName": "Sejuani's Berserkers",
"isVeteran": false,
"tier": "PLATINUM",
"lastPlayed": 1389198358615,
"playerOrTeamId": "32303008",
"leaguePoints": 64,
"rank": "V",
"isInactive": false,
"queueType": "RANKED_SOLO_5x5",
"playerOrTeamName": "Invicterr",
"wins": 462
}
],
"tier": "PLATINUM"
}
我的代碼:
for (Map.Entry<String, League> entry : leagues.entrySet())
{
try
{
if(Integer.parseInt(entry.getKey()) == 32303008)
{
System.out.println(entry.getKey() + "|" + entry.getValue());
}
}
catch(Exception e){}
}
步驟1)使用其中一個不同的工具包將JSON字符串轉換爲一組嵌套的地圖和數組。步驟2)通過地圖條目「32303008」,地圖條目「條目」,數組元素0,地圖條目「leaguePoints」的「鏈」訪問。等其他值。不需要迭代。 –