Reputation: 1
i am the following codes in javascript
var people = {
"users" : [{id : this.getJID().toString()},{id : this.getJID().toString()}],
"body" : messageBody
}
on my server end, I have the following:
JSONObject b = new JSONObject(jsonstring);
JSONArray users = b.getJSONArray("users");
I cannot get users because I will have the following exception.
org.json.JSONException: JSONObject["users"] is not a JSONArray.
I tried to cast to JSONObject but also gets error.
JSONObject o = b.getJSONObject("users");
org.json.JSONException: JSONObject["users"] is not a JSONObject.
What is wrong??
Upvotes: 0
Views: 7124
Reputation: 24627
As noted above:
The JSON is serialized wrongly. The value of user is not an array but a string: {"users":"[...]","body":"test"} There should be no quotes around [...]. That's why you get the error. It seems like you recursively serialized the contents of people
Upvotes: 1