0

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": "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"
}]
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
Nam Vu
  • 5,669
  • 7
  • 58
  • 90
  • 07-17 19:48:53.650: W/System.err(15185): org.json.JSONException: Value "xxxxxx" 07-17 19:48:53.660: W/System.err(15185): at org.json.JSON.typeMismatch(JSON.java:100) – Nam Vu Jul 16 '12 at 13:04
  • Share the Stacktrace. That may give us more details. – Santosh Gokak Jul 16 '12 at 13:06

4 Answers4

3

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
}
Community
  • 1
  • 1
Nermeen
  • 15,883
  • 5
  • 59
  • 72
1

That's not a JSON object - it's a JSON array containing two objects.

Use new JSONArray(resultString); first then get the objects from that.

Squonk
  • 48,735
  • 19
  • 103
  • 135
1

Hi [] denotes array in JSON, so after parsing try to put it in JSONArray... new JSONArray(resultString).getJSONObject(int index);

in this manner you can get JSON Object..

sandy
  • 3,311
  • 4
  • 36
  • 47
1

For parsing JSON I used GSON.

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

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

Volodymyr
  • 1,037
  • 1
  • 11
  • 27