Reputation: 7606
I am trying to parse a JSON object in my android application and I do so like this
JSONObject json = new JSONObject(jsonString);
the value of jsonString is:
[{"pk": 1, "model": "mydb.user", "fields": {"username": "willyb", "password": "tao1",
"signup_date": "2011-11-28 09:15:58", "email": "[email protected]"}}]
Is there an obvious reason why this is failing?
Upvotes: 2
Views: 875
Reputation: 137322
Because this is a JSONArray, not JSONObject. (See here)
You should do:
JSONArray arr = new JSONArray(jsonString);
JSONObject json = arr.get(0);
Upvotes: 2
Reputation: 23171
Your string is an array. Try:
JSONArray arr = new JSONArray(jsonString);
Upvotes: 1