Mam strumienia json, który może być coś takiego:test jeśli jest JSONObject lub JSONArray
{"intervention":
{
"id":"3",
"subject":"dddd",
"details":"dddd",
"beginDate":"2012-03-08T00:00:00+01:00",
"endDate":"2012-03-18T00:00:00+01:00",
"campus":
{
"id":"2",
"name":"paris"
}
}
}
lub coś
{"intervention":
[{
"id":"1",
"subject":"android",
"details":"test",
"beginDate":"2012-03-26T00:00:00+02:00",
"endDate":"2012-04-09T00:00:00+02:00",
"campus":{
"id":"1",
"name":"lille"
}
},
{
"id":"2",
"subject":"lozlzozlo",
"details":"xxx",
"beginDate":"2012-03-14T00:00:00+01:00",
"endDate":"2012-03-18T00:00:00+01:00",
"campus":{
"id":"1",
"name":"lille"
}
}]
}
W moim kodu Java I wykonaj następujące czynności:
JSONObject json = RestManager.getJSONfromURL(myuri); // retrieve the entire json stream
JSONArray interventionJsonArray = json.getJSONArray("intervention");
W pierwszym przypadku powyższe nie działa, ponieważ w strumieniu znajduje się tylko jeden element. Jak sprawdzić, czy strumień jest object
lub array
?
Próbowałem z json.length()
ale to nie działa ..
Dzięki
** ** Java, nie JavaScript. –
@ T.J.Crowder wow dziękuje, zbyt wcześnie rano, myślę. edytowana odpowiedź –
Dobra edycja, +1 ... –