本文介绍了解析一个有效的JSON时JSONException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试解析这个有效的JSON

我用新的JSONObject(resultString); ,但我有JSONException

我如何可以解析自己的Json

请帮助我!

感谢

  [{
    ID:8637F7F78C8C1
    from_account_id:1025630,
    to_account_id:1025635,
    transaction_type_id:15
    transaction_mode_id:2,
    transaction_status_id:1,
    量:1000.00,
    real_amount:1000.00,
    promote_amount:0.00,
    from_fix_fee_amount:0.00,
    from_percent_fee_amount:50.00,
    to_fix_fee_amount:0.00,
    to_percent_fee_amount:0.00,
    说明:演示,
    created_on:2012-07-16 10时04分29秒,
    activated_on:0000-00-00 00:00:00,
    executed_on:0000-00-00 00:00:00,
    verify_transaction_by:O,
    from_account_name:XXXXXXXXXXXX
    from_account_email:[email protected]
    from_account_phone_no:xxcxxxxxx,
    to_account_name:YYYYYYY,
    to_account_email:[email protected]
    to_account_phone_no:YYYYYYYY
},
{
    ID:A26BF7F75534B
    from_account_id:1014635,
    to_account_id:1054630,
    transaction_type_id:5,
    transaction_mode_id:2,
    transaction_status_id:4,
    量:1000.00,
    real_amount:1000.00,
    promote_amount:0.00,
    from_fix_fee_amount:0.00,
    from_percent_fee_amount:0.00,
    to_fix_fee_amount:0.00,
    to_percent_fee_amount:0.00,
    说明:,
    created_on:2012-07-15 0时52分四十秒,
    activated_on:2012-07-15○时53分19秒,
    executed_on:2012-07-15 0点54分57秒,
    verify_transaction_by:O,
    from_account_name:YYYYYY,
    from_account_email:[email protected]
    from_account_phone_no:YYYYYYY,
    to_account_name:wwwwwww,
    to_account_email:[email protected]
    to_account_phone_no:YYYYYYYYY
}]


解决方案

这是一个 JSONArray 不是的JSONObject 。 。结果

  JSONArray值=新JSONArray(resultString);
的for(int i = 0; I< values​​.length();我++){
    的JSONObject对象=(JSONObject的)values​​.get(I)
    字符串ID = object.getString(ID);
    //同为休息
}

I try to parse this valid JSON

I use new JSONObject(resultString); but i have JSONException

How can i parse his Json

Help me please!

Thanks

[{
    "id": "8637F7F78C8C1",
    "from_account_id": "1025630",
    "to_account_id": "1025635",
    "transaction_type_id": "15",
    "transaction_mode_id": "2",
    "transaction_status_id": "1",
    "amount": "1000.00",
    "real_amount": "1000.00",
    "promote_amount": "0.00",
    "from_fix_fee_amount": "0.00",
    "from_percent_fee_amount": "50.00",
    "to_fix_fee_amount": "0.00",
    "to_percent_fee_amount": "0.00",
    "description": "demo",
    "created_on": "2012-07-16 10:04:29",
    "activated_on": "0000-00-00 00:00:00",
    "executed_on": "0000-00-00 00:00:00",
    "verify_transaction_by": "o",
    "from_account_name": "xxxxxxxxxxxx",
    "from_account_email": "[email protected]",
    "from_account_phone_no": "xxcxxxxxx",
    "to_account_name": "yyyyyyy",
    "to_account_email": "[email protected]",
    "to_account_phone_no": "yyyyyyyy"
},
{
    "id": "A26BF7F75534B",
    "from_account_id": "1014635",
    "to_account_id": "1054630",
    "transaction_type_id": "5",
    "transaction_mode_id": "2",
    "transaction_status_id": "4",
    "amount": "1000.00",
    "real_amount": "1000.00",
    "promote_amount": "0.00",
    "from_fix_fee_amount": "0.00",
    "from_percent_fee_amount": "0.00",
    "to_fix_fee_amount": "0.00",
    "to_percent_fee_amount": "0.00",
    "description": "",
    "created_on": "2012-07-15 00:52:40",
    "activated_on": "2012-07-15 00:53:19",
    "executed_on": "2012-07-15 00:54:57",
    "verify_transaction_by": "o",
    "from_account_name": "yyyyyy",
    "from_account_email": "[email protected]",
    "from_account_phone_no": "yyyyyyy",
    "to_account_name": "wwwwwww",
    "to_account_email": "[email protected]",
    "to_account_phone_no": "yyyyyyyyy"
}]
解决方案

it's a JSONArray not a JSONObject ..
JSON Array iteration in Android/Java

JSONArray values = new JSONArray(resultString);
for(int i = 0 ; i < values.length(); i++){
    JSONObject object = (JSONObject) values.get(i); 
    String id = object.getString("id");
    //the same for the rest
}

这篇关于解析一个有效的JSON时JSONException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 18:14