anewbie
anewbie

Reputation: 1

Why is this JSONObject not a JSONArray?

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

Answers (1)

Paul Sweatte
Paul Sweatte

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

Related Questions