JSON data cannot

I am writing a program to capture a JSON response from a server that contains some information I need. I found that someday my program will not be able to capture the correct JSON string, and someday it will work without problems. I am trying to check my code for a response and have no idea. When I check the JSON string from the server, it contains the field that I want, but my program cannot display the correct data.

This is my JSON string

"info":{  
      "reason":"Fine",
      "boolean":false,
      "post":{  
         "actions":"",
         "actions_In_process":"Checked",
         "destination":"C%3ApdfFdoc%20edipdfFdestinationpdfFexample.pdf",
         "file_type":"pdf",
       
      },

This is my JSON string capture program and I need a field action_In_process

String Url1 = "http://IP:port/etc/";
HttpURLConnection con = (HttpURLConnection) Url1.openConnection();  
con.setRequestMethod("GET");
con.connect();
int responseCode = con.getResponseCode();
if(responseCode == 200)
{
  try
   {
     InputStream is = con.getInputStream();
     BufferedReader read = new BufferedReader (new InputStreamReader(is));
     StringBuffer buffer = new StringBuffer();
     String data = "" ; 
     while((data = read.readLine() ) != null )
     {
         buffer.append(data);
     }

     String JsonData = buffer.toString();
     JSONObject jobj = new JSONObject(JsonData);
     JSONObject process_info = jobj.getJSONObject("info");
     JSONObject pi = process_info.getJSONObject("post");
     String action_run = pi.getString("actions_In_process");
     System.out.println("Process:" +action_run);

What I found out was once showing the process is empty, but when I return the JSON data, and I find out that I need a field inside the JSON response. Please share your opinion on these issues.

, , JSON

Process : 

Process : check
+4
1

BufferedReader readline() .

-1

Source: https://habr.com/ru/post/1664511/


All Articles