我的javascript代码如下
var people = {
"users" : [{id : this.getJID().toString()},{id : this.getJID().toString()}],
"body" : messageBody
}
在我的服务器端,我有以下内容:
JSONObject b = new JSONObject(jsonstring);
JSONArray users = b.getJSONArray("users");
我无法获得用户,因为我会遇到以下异常。
org.json.JSONException: JSONObject["users"] is not a JSONArray.
我尝试转换为 JSONObject 但也出现错误。
JSONObject o = b.getJSONObject("users");
org.json.JSONException: JSONObject["users"] is not a JSONObject.
怎么了?
最佳答案
如上所述:
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
关于java - 为什么这个 JSONObject 不是 JSONArray?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6952973/