0

我是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"] 不是 JSONArray。

我试图转换为 JSONObject 但也出现错误。

JSONObject o = b.getJSONObject("users");

org.json.JSONException: JSONObject["users"] is not a JSONObject.

怎么了??

4

1 回答 1

1

如上所述:

JSON 序列化错误。user 的值不是数组而是字符串: {"users":"[...]","body":"test"} [...] 周围不应该有引号。这就是你得到错误的原因。好像你递归序列化了人们的内容

于 2014-10-06T19:01:21.163 回答