how to manipulate HTTP json response data in Java
http, httpresponse, java, json
Solution
You may use this JSON library to parse your json string into JSONObject and read value from that object as show below :
JSONObject json = new JSONObject(EntityUtils.toString(entity));
JSONObject sessionObj = json.getJSONObject("session");
System.out.println(sessionObj.getString("name"));
You need to read upto that object from where you want to read value. Here you want the value of `name` parameter which is inside that `session` object, so you first get the value of `session` as JSONObject using getJSONObject(KeyString) and read `name` value from that object using function getString(KeyString) as show above.
May this will help you.
Problem
``` HttpGet getRequest=new HttpGet("/rest/auth/1/session/"); getRequest.setHeaders(headers); httpResponse = httpclient.execute(target,getRequest); entity = httpResponse.getEntity(); System.out.println(EntityUtils.toString(entity)); ``` Output as follows in json format ``` ---------------------------------------- {"session":{"name":"JSESSIONID","value":"5F736EF0A08ACFD7020E482B89910589"},"loginInfo":{"loginCount":50,"previousLoginTime":"2014-11-29T14:54:10.424+0530"}} ---------------------------------------- ``` What I want to know is how to you can manipulate this data using Java without writing it to a file? I want to print name, value in my code Jackson library is preferred but any would do. thanks in advance