1

I'm trying to read the json response of a request post. This is the code ...

        connection.getOutputStream().write(paramDataBytes);
        Reader in = new BufferedReader(new InputStreamReader (connection.getInputStream(),"UTF-8"));
        StringBuilder sb = new StringBuilder();
        for(int c;(c=in.read())>=0;)
            sb.append((char)c);
        String response = sb.toString();
        System.out.println(response);
        JSONObject myResponse = new JSONObject(response.toString());

but the of response variable is

"?; ?m???×"}?iU?(s? ?0?p?6]p????E??*?Q????*U@?g?-x??1D@ ?H??P?{?a?P??w?KV?"

why?

when I try to create the object "JSONObject myResponse " I have the following error

Exception in thread "main" org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
    at org.json.JSONTokener.syntaxError(JSONTokener.java:505)
    at org.json.JSONObject.<init>(JSONObject.java:215)
    at org.json.JSONObject.<init>(JSONObject.java:399)
    at com.application.HttpRequestRaffle.main.Main2.main(Main2.java:83)

I desperately need help...

this is the response of the request that I do manually through firefox

enter image description here

4
  • 2
    Are you sure the called URL returns valid json output? Maybe the error is not on your side.. I have also found this example of calling an URL to get json response, it uses json parser, but if you will get an text as you mentioned, then it will not be working for sure Commented Jun 14, 2018 at 10:30
  • 2
    in the image I have inserted there is the response Commented Jun 14, 2018 at 10:53
  • 1
    i have resolve, the response was compressed. Commented Jun 29, 2018 at 9:12
  • Hi, thanks for followup and feedback, if possible please put it as a answer and once it will be possible accept it by your own. That will help for proper post filtering, etc.. Commented Jun 29, 2018 at 9:38

2 Answers 2

1

i have resolve, the response was compressed.

Sign up to request clarification or add additional context in comments.

Comments

0

-- as you can see in comments Its resolved,

@Frato: "i have resolve, the response was compressed. – Frato"

Putting separate answer post to prevent new answers

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.