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
How to Pass List in Postman in Get Request and Get in Getmapping
Pass Multiple Parameters to Rest API - Spring
Parameter 0 of Constructor in Required a Bean of Type 'Java.Lang.String' That Could Not Be Found
Arraylist - How to Check If an Index Exists
Why Do I Get 404 for Rest With Spring-Boot
How to Update Only the Incoming Fields in a Model Using Spring Data Jpa
Field Required a Bean Which Could Not Be Found in Springboot
Maven Build Cannot Find Symbol When Accessing Project Lombok Annotated Methods,
Error Starting Applicationcontext in Spring Boot App
Loop Over All Fields in a Java Class
Error About Sun/Misc/Base64Encoder on Eclipse
Wait Until All Threads Finish Their Work in Java
How to Return a Select Query from JPA Repository With Foreign Key Type
Generate 6 Digit Random Number
Could Not Open JPA Entitymanager for Transaction (Using Localcontainerentitymanagerfactorybean)
Expiry Time @Cacheable Spring Boot