org.json.JSONException: A JSONArray text must start with '['

www.laut‮moc.irut‬
org.json.JSONException: A JSONArray text must start with '['

Error Message

Exception in thread "main" org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]
	at org.json.JSONTokener.syntaxError(JSONTokener.java:501)
	at org.json.JSONArray.<init>(JSONArray.java:89)
	at org.json.JSONArray.<init>(JSONArray.java:142)
	at hello.Lautturi.main(Lautturi.java:87)

Error Code

String jsonString = "{\"id\":111,\"name\":\"Lautturi\"}";
JSONArray data = new JSONArray(jsonString);

Cause

The json string should begin with [ (left bracket) and ends with ] (right bracket).

Solution

``` java
String jsonString = "[{\"id\":111,\"name\":\"Lautturi\"}]";
Created Time:2017-10-03 13:31:09  Author:lautturi