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

Sandip Armal Patil picture Sandip Armal Patil · Dec 23, 2012 · Viewed 27.8k times · Source

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.

Answer

thepoosh picture thepoosh · Dec 23, 2012

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