我有一個解析Android中的JSON對象的堆棧。如何在android中解析JSON(Two Dimessional)數組對象?
這裏我JSON數據,
{
STATUS: "200"
ERROR: "false"
SECRETKEY: "deb1d0b9a70a0ed682d2975b2a583c28"
DATA: {
stock: 2
pins: [1]
0: {
id: "1"
pin: "8172310874"
serial: "0000000000100000"
card_type: "10000"
company: "FWIFI"
expiry_date: "2016-01-01"
invoice_id: "INVHQ/000001"
order_id: "1"
delivered: "0"
}
}
}
這裏我解析JSON對象
try {
JSONObject json = new JSONObject(value);
String secretKey = json.get("SECRETKEY").toString();
JSONObject data_obj = new JSONObject("DATA"); //problem is here. It's go to catch block
JSONArray j_array = data_obj.getJSONArray("pins");
Integer qty = j_array.length();
for(int i = 0 ; i < j_array.length() ; i++){
//here loop
}
}catch (JSONException e) {
e.printStackTrace();
}
請指點我,我環路怎麼可以?我改變這一點。但是,錯誤就是這樣說的。
java.lang.String類型的值數據不能被轉換爲JSONObject的
'{'是'jsonObject',而不是'jsonArray' –