Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 409
Sandip Armal Patil Avatar asked Dec 23 '12 07:12

Sandip Armal Patil


3 Answers

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).

like image 99
thepoosh Avatar answered Oct 14 '22 05:10

thepoosh


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;
    }
like image 9
Zin Win Htet Avatar answered Oct 14 '22 04:10

Zin Win Htet


I use jsoneditoronline online tool that works pretty good.

enter image description here

like image 4
Maxim Shoustin Avatar answered Oct 14 '22 04:10

Maxim Shoustin