10

我正在从 web 服务中获取数据,并将其解析为 JSON 字符串。解析时我是这个异常:“org.json.JSONException: Unterminated string at character 1834”

我的代码是,

String jsonstring=getJSONString(response);

JSONObject json = new JSONObject(jsonstring);

字符串是,

[{"LotDescription":"David Weekley homes Traditional Collection in Baxter Village offers floor plans featuring innovative design and unsurpassed quality. This charming community combines work, play and living, all within the Village. In Baxter Village, you’ll enjoy:  Parks, playgrounds"}]

它一直解析到“Village”一词,并在解析“you'll”时引发异常,这似乎是一些 HTML 内容。

解决方案是什么?

4

2 回答 2

4

您需要添加字符\

[{"LotDescription":\"David Weekley homes Traditional Collection in Baxter Village offers floor plans featuring innovative design and unsurpassed quality. This charming community combines work, play and living, all within the Village. In Baxter Village, you’ll enjoy:  Parks, playgrounds\"}]

这会做。

于 2013-05-21T07:12:11.093 回答
2

你的 Json 不是一个,JSONObject而是一个JSONArray.
试试这个:

JSONArray jObject = new JSONArray(jsonstring);
        for (int i = 0; i < jObject.length(); i++) {
             JSONObject object = jObject.getJSONObject(i);

             String LotDescription = menuObject.getString("LotDescription");
         }
于 2013-05-21T07:18:04.103 回答