Ich versuche, Multilevel JSON (Von Quandl) zu parsonieren, aber ich habe Schwierigkeiten, es richtig zu analysieren.Parsing Multi Layered JSON
Der Teil, ich kann nicht herausfinden, wie zu analysieren ist unter dem Daten-Tag. Wie wähle ich es aus und iteriere durch alle Werte, da sie keine Schlüsselpaare sind.
Dieser Abschnitt des Codes erwartet eine int
stockArray.getJSONArray("data");
Jede Hilfe wird sehr geschätzt.
Dies ist, was ich jetzt bin versucht:
JSONObject stockObject = new JSONObject(result);
JSONArray stockArray = stockObject.getJSONArray("dataset");
JSONArray statsArray = stockArray.getJSONArray("data");
for(int i = 0; i < statsArray.length(); i++){
JSONArray arr = statsArray.getJSONArray(i);
for(int j = 0; j < arr.length(); j++){
Log.d("TAG", arr.getString(j));
}
}
Dies ist die json:
{
"dataset":{
"id":9792521,
"dataset_code":"KIBO",
"database_code":"LSE",
"name":"KIBO MINING share price (KIBO), Currency GBX",
"description":"Stock Prices for Kibo Mining Share Price (kibo), Currency Gbx from the London Stock Exchange.\u003cbr\u003e\u003cbr\u003eCurrency: GBX",
"refreshed_at":"2016-05-11T21:52:53.568Z",
"newest_available_date":"2016-05-11",
"oldest_available_date":"2010-04-27",
"column_names":[
"Date",
"Price",
"High",
"Low",
"Volume",
"Last Close",
"Change",
"Var%"
],
"frequency":"daily",
"type":"Time Series",
"premium":false,
"limit":10,
"transform":null,
"column_index":null,
"start_date":"2010-04-27",
"end_date":"2016-05-11",
"data":[
[
"2016-05-11",
4.0,
4.25,
3.88,
434000.0,
4.0,
0.0,
0.0
],
[
"2016-05-10",
4.0,
4.25,
3.88,
1611062.0,
4.0,
0.0,
0.0
],
[
"2016-05-09",
4.0,
4.25,
4.0,
2005382.0,
4.0,
-0.25,
-5.88
],
[
"2016-05-06",
4.25,
4.5,
4.12,
743687.0,
4.25,
0.12,
3.03
],
[
"2016-05-05",
4.12,
5.12,
4.12,
5731469.0,
4.12,
-1.0,
-19.51
],
[
"2016-05-04",
5.12,
6.25,
4.88,
5348475.0,
5.12,
-0.62,
-10.87
],
[
"2016-05-03",
5.75,
6.0,
5.38,
4313650.0,
5.75,
0.38,
6.98
],
[
"2016-04-29",
5.38,
5.5,
5.0,
3654596.0,
5.38,
0.25,
4.88
],
[
"2016-04-28",
5.12,
5.38,
4.75,
2298599.0,
5.12,
0.25,
5.13
],
[
"2016-04-27",
4.88,
4.88,
4.25,
3586011.0,
4.88,
0.62,
14.71
]
],
"collapse":null,
"order":"desc",
"database_id":384
}
}
warum in der ersten Zeile Ihr eine JSONObject in ein JSONArray Parsen? Ich denke, das ist dein Problem ... – Jim