Ich habe eine JSON-Datei wie:Wie parsen wir JSON ohne JSONArray in Java?
{
"a1" : {
"Contestant 1 marks" : 44,
"Contestant 10 marks" : 30,
"Contestant 11 marks" : 15,
"Contestant 12 marks" : 35,
"Contestant 13 marks" : 28,
"Contestant 14 marks" : 8,
"Contestant 2 marks" : 35,
"Contestant 3 marks" : 30.899999618530273,
"Contestant 4 marks" : 39,
"Contestant 5 marks" : 45,
"Contestant 6 marks" : 47,
"Contestant 7 marks" : 17,
"Contestant 8 marks" : 37,
"Contestant 9 marks" : 35
},
"a2" : {
"Contestant 1 marks" : 35,
"Contestant 10 marks" : 30,
"Contestant 11 marks" : 15,
"Contestant 12 marks" : 35,
"Contestant 13 marks" : 28,
"Contestant 14 marks" : 8,
"Contestant 2 marks" : 30,
"Contestant 3 marks" : 30.899999618530273,
"Contestant 4 marks" : 39,
"Contestant 5 marks" : 45,
"Contestant 6 marks" : 47,
"Contestant 7 marks" : 17,
"Contestant 8 marks" : 37,
"Contestant 9 marks" : 35
}
}
Es scheint, als ob es zwei JSON-Objekte hier a1, a2. Und diese Objekte selbst haben 14 JSON-Objekte.
Ich habe eine String completeJson;
, die komplette JSON enthält.
Nun, wenn ich schreibe
JSONObject jsonRootObj = new JSONObject(completeJson);
Dann whilch json Objekt in jsonRootObj kommen wird?
Wie bekomme ich auch den Wert für den Schlüssel: "Kandidat 1 Marken" für a1 und a2 in meiner JSON-Datei?
Ich möchte den Wert der Objekte in a1
mit Wert der Objekte in a2
, die die gleiche KEY haben.
jsonRootObj.get ("a1"). Get ("Kandidat 1 Marks"), da die von Ihnen gepostete JSON kein Array enthält –
Entschuldigung, Sie müssen Folgendes umsetzen: ((JSONObject) jo.get ("a1")) .get ("Kandidat 1 Noten") –