dmaprasad dmaprasad - 4 months ago 8
JSON Question

"Disallowed Key Characters" error in json output

I'm trying to execute API and try to get

response, but I'm getting error as
"Disallowed Key Characters"

Following is the code that I'm trying to use. But when I run the request url in web browser I'm getting response without issue.But by using java code I'm unable to extract data. Please help

String uri = ""
+ mobile;
URL url;
Gson json = null;
try {
url = new URL(uri);
json = new Gson();

HttpURLConnection connection;
access_token = db.getAccessTokenFromDB();
connection = (HttpURLConnection) url.openConnection();

System.out.println("URL:" + uri);

connection.setRequestProperty("Content-Type", "application/json");
int status = connection.getResponseCode();
resCode = Integer.toString(status);

InputStream in = connection.getInputStream();
BufferedReader bf = new BufferedReader(
new InputStreamReader(in));
System.out.println("bf.readLine() - "+bf.readLine());

while ((output = bf.readLine()) != null) {
JSONObject obj = new JSONObject(output);
System.out.println("output is "+output);
resCode = obj.getString("resCode");
resDesc = obj.getString("COUNT");




try this

BufferedReader in = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));

instead of

 BufferedReader bf = new BufferedReader(new InputStreamReader(in));

because you need to add encoding technique by which a BufferedReader able to encode any special character in proper format.

Hope this might help you.

Thank You.