org.json.JSONException: Expected literal value at character 550 of

无人久伴 提交于 2020-01-01 09:44:53

问题


I am trying to read JSON file from asset folder. But I get the following exception
org.json.JSONException: Expected literal value at character 550
I searched lot of stuff but didn't find anything relative. Here is my JSON file.

I find JSON object on 550 is "names": ["Santosh","Sandip","Arvind"],. I am trying to solve it but don't know what happens in my code.
Here is my code.

I also debug my code but when control goes on JSONObject jsonObject = new JSONObject(text); it throw exception and goes in first catch block.
Please give me any reference or hint to solve this problem.
Any help appreciated.


回答1:


your JSON is invalid.
your JSON should look like this

{
    "resultCount": 3,
    "SearchedTerm": "Wada Pav",
    "results": [
        {
            "locationname": "Mahableshwar Hotel",
            "locationid": "12345",
            "locationaddress": "baner, Pune",
            "dishrating": "4",
            "dishname": "Wada Pav",
            "dishid": "234",
            "dishcategory": "Snacks",
            "dishnotes": "Spicy Wada Pav",
            "dishpreviewurl": "http://xxx.yyy.zzz/mahableshwar/1.jpg",
            "dishtotalvotes": "9999",
            "friendslistvoted": {
                "friendscount": "3",
                "names": [
                    "Santosh",
                    "Sandip",
                    "Arvind"
                ]
            },
            "dishimageurl": "http://xxx.yyy.zzz/mahableshwar/2.jpg",
            "mylastrating": "4"
        }
    ]
}

try using a JSON validator before using it (like JSLint).




回答2:


I'm using following to get standard JSON format. This one is better.

    public static String convertStandardJSONString(String data_json) {
        data_json = data_json.replaceAll("\\\\r\\\\n", "");
        data_json = data_json.replace("\"{", "{");
        data_json = data_json.replace("}\",", "},");
        data_json = data_json.replace("}\"", "}");
        return data_json;
    }



回答3:


I use jsoneditoronline online tool that works pretty good.




回答4:


this works for me

    public static String convertJSONString(String data) {
    data = data.replace("\\", "");
    return data; }


来源:https://stackoverflow.com/questions/14009352/org-json-jsonexception-expected-literal-value-at-character-550-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!