我想动态解析我的 Json 数组。并希望为 jsonarray 下的每个元素获取 KEYS 数组。我通过迭代器得到这个。但没有根据输出的 json 格式获得序列。
我的 JSON 格式:
{
"result": "Success",
"AlertDetails": [
{
"ShipmentNumber": "SHP34",
"Customer": "BEST",
"DateCreated": "2012-08-29T04:59:18Z"
"CustomerName": "BEST"
},
{
"ShipmentNumber": "SHP22",
"Customer": "BEST",
"DateCreated": "2012-08-29T05:34:18Z"
"CustomerName": "Jelly"
}
]
}
这是我的代码:
JSONArray array = jsonobject.getJSONArray("AlertDetails");
JSONObject keyarray = array.getJSONObject(0);
Iterator temp = keyarray.keys();
while (temp.hasNext()) {
String curentkey = (String) temp.next();
KEYS.add(curentkey);
}
Log.d("Parsing Json class", " ---- KEYS---- " + KEYS);
我在 logcate 输出中得到什么:
---- KEYS---- [DateCreated,CustomerName, Customer, ShipmentNumber]
我想要的是 :
---- KEYS---- [ShipmentNumber, Customer, DateCreated,CustomerName]