I am trying to convert a byte[]
to JSON that looks like: {"foo": [{...}, {...}, ...], "bar": []}
try {
byte[] response = getExternalServiceResponse();
JSONObject json = new JSONObject(new String(response));
log.info(json.toString(4));
} catch (Exception e) {
e.printStackTrace();
}
This works for most cases of response but there are some that throw the exception with org.json.JSONException: A JSONObject text must begin with '{' at 3 [character 2 line 2]
. How can I find out what characters are causing the issue as I can't read a byte array and I am not sure what the input contains without first converting it to JSON which throws the error?