我有可能會像JSON流:測試,如果它是的JSONObject或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"
}
}
}
或類似
{"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"
}
}]
}
在我的Java代碼中,我做到以下幾點:
JSONObject json = RestManager.getJSONfromURL(myuri); // retrieve the entire json stream
JSONArray interventionJsonArray = json.getJSONArray("intervention");
在第一情況下,上述不工作,因爲在流中只有一個元素是.. 如何檢查,如果流是object
或array
?
我試着用json.length()
,但它沒有工作..
感謝
** **的Java,JavaScript不。 – 2012-04-03 06:44:01
@ T.J.Crowder哇感謝,早上我想太早。編輯答案 – 2012-04-03 06:49:21
好編輯,+1 ... – 2012-04-03 06:51:35