A Jsonobject Text Must Begin With '{' At 1 [Character 2 Line 1] With '{' Error

A JSONObject text must begin with '{' at 1 [character 2 line 1] with '{' error

Your problem is that String JSON = "http://www.json-generator.com/j/cglqaRcMSW?indent=4"; is not JSON.

What you want to do is open an HTTP connection to "http://www.json-generator.com/j/cglqaRcMSW?indent=4" and parse the JSON response.

String JSON = "http://www.json-generator.com/j/cglqaRcMSW?indent=4";
JSONObject jsonObject = new JSONObject(JSON); // <-- Problem here!

Will not open a connection to the site and retrieve the content.

Error Message: A JSONObject text must begin with '{' at 1 [character 2 line 1]

there are a couple of things.

First of all, your json Object is getting the url, not the response.

JSONObject json = new JSONObject(sURL);

For Json you cannot parse line by line, you need to get the whole response.

The response should be something like:

yc.getContent()  

When you get the input stream, you are trying to pass values to the URL, not get the results back.

Error: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]

You have extra "[" and "]"

[{"accountId":"1000"....ate":"PENDING"}]

json should start and end with {}
Then this will work:

JSONObject jsonObject = new JSONObject(content);

Or you should first read JSONArray and then read the JSONObject as an item from this Array

JSONArray jsonArray = new JSONArray(content);
JSONObject json = jsonArray.getJSONObject(0);// 0 - index of the json item inside JSONArray

A JSONObject text must begin with '{' error

I suppose that you should use not JSONObject, but JSONArray



Related Topics



Leave a reply



Submit