我面臨着一些問題,同時解析JSON值,請找到下面的JSON文件,無法解析JSON值的Android
{
"Account": "xxx",
"Account_desc": "xxx",
"TimeZone": "GMT+05:30",
"DeviceList": [
{
"Device": "xttt",
"Device_desc": "txtx",
"EventData": [
{
"Device": "xttt",
"Timestamp": 1373539125,
"Timestamp_date": "2013/07/11",
"Timestamp_time": "16:08:45",
"StatusCode": 61715,
"StatusCode_hex": "0xF113",
"StatusCode_desc": "Stop",
"GPSPoint": "12.97887,77.51030",
"GPSPoint_lat": 12.97887,
"GPSPoint_lon": 77.51030,
"Speed": 0.0,
"Speed_units": "km/h",
"Odometer": 3.416,
"Odometer_units": "Km",
"Geozone": "zone4",
"Geozone_index": 0,
"Address": "cxcxc",
"DigitalInputMask": 251,
"DigitalInputMask_hex": "0xFB",
"Index": 0
}
]
},
{
"Device": "pppp",
"Device_desc": "statstr",
"EventData": [
{
"Device": "pppp",
"Timestamp": 1368870217,
"Timestamp_date": "2013/05/18",
"Timestamp_time": "15:13:37",
"StatusCode": 61715,
"StatusCode_hex": "0xF113",
"StatusCode_desc": "Stop",
"GPSPoint": "14.26281,80.11421",
"GPSPoint_lat": 14.26281,
"GPSPoint_lon": 80.11421,
"Speed": 0.0,
"Speed_units": "km/h",
"Odometer": 373.874,
"Odometer_units": "Km",
"Geozone": "port",
"Geozone_index": 0,
"Address": "asdfsdfss",
"Index": 0
}
]
}
]
}
從上面的JSON,我想有隻「GPSPoint_lat」,」 GPSPoint_lon」和‘’中‘EVENTDATA’所以我做了編碼如下設備,
JSONObject jsonObject = ApplicationContext.getHttpService()
.readAsJson(s);
// System.out.println("indexvalue:"+s.indexOf(1,5));
// JSONObject object = jsonObject.getJSONObject("DeviceList");
JSONArray jsonArray = jsonObject.getJSONArray("DeviceList");
JSONObject object = jsonArray.getJSONObject(0);
JSONArray secondarray = object.getJSONArray("EventData");
for (int i = 0; i < secondarray.length(); i++) {
try {
System.out.println("Im...");
// System.out.println("Latitude:"+ ((JSONObject)
// jsonArray.get(i)).getString("GPSPoint_lat"));
// String id = ((JSONObject)
// jsonArray.get(i)).getString("deviceID");
// arr = (JSONArray) jsonArray.get(i);
JSONObject obj = secondarray.getJSONObject(i);
String lat = obj.getString("GPSPoint_lat");
String lon = obj.getString("GPSPoint_lon");
........//..
...///......}}
但問題在上面的代碼是每當我執行我收到arraylength爲1,即只得到我的意思是第一個Eventdata值。我需要的是我想獲得所有「Eventdata」值。請就此提出建議。
問候 普里亞
非常感謝你...你在晃動 – user2918730
@ user2918730歡迎並接受我的回答.. – Hariharan