0

この有効なJSONを解析しようとしています

使用していますnew 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",
    "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": "xxxxxxx@gmail.com",
    "from_account_phone_no": "xxcxxxxxx",
    "to_account_name": "yyyyyyy",
    "to_account_email": "yyyyy@gmail.com",
    "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": "yyyyyy@gmail.com",
    "from_account_phone_no": "yyyyyyy",
    "to_account_name": "wwwwwww",
    "to_account_email": "yywywyyy@gmail.com",
    "to_account_phone_no": "yyyyyyyyy"
}]
4

4 に答える 4

3

それは..Android/JavaでのJSON配列の反復でJSONArrayはありませんJSONObject

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
}
于 2012-07-16T13:00:08.227 に答える
1

これはJSONオブジェクトではなく、2つのオブジェクトを含むJSON配列です。

最初に使用new JSONArray(resultString);してから、そこからオブジェクトを取得します。

于 2012-07-16T13:00:39.853 に答える
1

こんにちは[]はJSONの配列を示しているので、解析した後、JSONArrayに入れてみてください...new JSONArray(resultString).getJSONObject(int index);

このようにして、JSONオブジェクトを取得できます。

于 2012-07-16T13:05:17.387 に答える
1

JSONの解析には、GSONを使用しました。

JsonElement jelement = new JsonParser().parse("json text");

JsonArray array = jobject.getAsJsonArray( "myarray");
for(JsonElement item:array){...}

于 2012-07-16T13:06:37.893 に答える