My code below is using Java's URLConnection to ping a RESTful API which will return a JSON string. The JSON string that I get back appears to be completely valid, but fails in both JSONLint and the final line of code below.
The returned JSON is:
{ "rowId": "1-12C-1494" }
The error message is:
Parse error on line 2: ...rowId": "1-12C-1494" -----------------------^ Expecting '}', ':', ',', ']'
The code is:
StringBuilder responseBuilder = new StringBuilder();
URLConnection connection = url.openConnection();
InputStream cin = connection.getInputStream();
int bytesRead = -1;
byte[] buffer = new byte[1024];
while ((bytesRead = cin.read(buffer)) >= 0) {
responseBuilder.append(new String(buffer, "UTF-8"));
}
String response = responseBuilder.toString();
JsonObject jsonObject = new JsonParser().parse(response).getAsJsonObject();
If I ping the RESTful API from a browser and copy the JSON there into JSONLint it validates just fine. The best I can tell this some kind of character/whitespace encoding issue. Has anyone else run into it and have any guidance? Thanks!