gpt4 book ai didi

android - 组织.json.JSONException : Unterminated object at character on Android

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:45:55 25 4
gpt4 key购买 nike

我解析 JSON 字符串并遇到错误

org.json.JSONException:字符 25 处未终止的对象

我的 JSON 是从 Facebook 检索的

{Response:  responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[{"venue":{"id":108242939200809,"zip":"","longitude":11.4,"latitude":62.5833,"street":""},"location":"Røros, Norway","eid":1473462312875161,"pic_big":"https:\/\/fbcdn-profile-a.akamaihd.net\/static-ak\/rsrc.php\/v2\/yn\/r\/5uwzdFmIMKQ.png","pic_small":"https:\/\/fbcdn-profile-a.akamaihd.net\/static-ak\/rsrc.php\/v2\/yy\/r\/XcB-JGXohjk.png","description":"Test","name":"Test"},{"venue":{"id":105818232792451,"zip":"","longitude":108.217,"latitude":16.0167,"street":""},"location":"Hòa Vang","eid":1425682134338854,"pic_big":"https:\/\/fbcdn-profile-a.akamaihd.net\/static-ak\/rsrc.php\/v2\/yn\/r\/5uwzdFmIMKQ.png","pic_small":"https:\/\/fbcdn-profile-a.akamaihd.net\/static-ak\/rsrc.php\/v2\/yy\/r\/XcB-JGXohjk.png","description":"test","name":"Test"}]}}, error: null, isFromCache:false}

我的 JSON 解析器是

public static JSONArray parse(Response response) throws JSONException{          
JSONArray jsonArray=new JSONArray(response.toString());
return jsonArray;
}

请帮帮我。非常感谢。

最佳答案

这可能是因为您在使用 response.toString()response 转换为 String 后尝试解析 response

所以如果您的响应

{"title":"这是标题","message":"这是消息"}

然后您使用 response.toString() 将其转换为 String

那么你的响应会是这样的

{title:This is Title,message:This is message}

因此,您正在尝试解析 String 类型的 response,编译器将无法解析该 response,它将 抛出一个错误,比如Unterminated object at character......

因此请确保您正在解析有效的 JSON。

EDIT ( Credit : Dhruv Raval for below edited solution )

您可以通过以下方式解决此问题:

之前:

GraphResponse response;
JSONObject jObjResponse = new JSONObject(response.toString());

之后:

GraphResponse response;
JSONObject jObjResponse = new JSONObject(String.valueOf(response.getJSONObject()));

关于android - 组织.json.JSONException : Unterminated object at character on Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22368305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com