2

Json Object:

{"SessionID":"ae231c4b-6c69-4dec-8d52-be0786cdcdd8",
"RequestUniqueID":"34356566545677",
"ReportCode":"01",
"Condition":"{\"ReferenceNumber\":\"500\"}",
"MethodName":"TopupGetReport"}

I want to parse this object; how do I do so?

1 Answer 1

1
  String response = "{\"SessionID\":\"ae231c4b-6c69-4dec-8d52-be0786cdcdd8\",\"RequestUniqueID\":\"34356566545677\",\"ReportCode\":\"01\",\"Condition\":{\"ReferenceNumber\":\"500\"},\"MethodName\":\"TopupGetReport\"}";
  try {
     JSONObject obj = new JSONObject(response);
     String sessionId = obj.getString("SessionID");
     String rqstUniqueId = obj.getString("RequestUniqueID");
     String reportCode = obj.getString("ReportCode");
     String methodName = obj.getString("MethodName");
     JSONObject condition = obj.getJSONObject("Condition");
     String referenceNumber = condition.getString("ReferenceNumber");

     System.out.println(sessionId + ", " + rqstUniqueId + ", " + reportCode + ", " + methodName + ", " + referenceNumber);
  } catch (JSONException e) {
     e.printStackTrace();
  }

which yields:

ae231c4b-6c69-4dec-8d52-be0786cdcdd8, 34356566545677, 01, TopupGetReport, 500

Note: I assume that a couple extra quotes around the brackets defining the Condition data were just a mistake, probably copied from some test code, into your question. I removed them (see my response string).

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

2 Comments

Hello it is json object which will cum from server side and then i have to post it using hash table so how to do it????
@NancyJain, If you are getting the JSON from a server, then the variable named response that I show above would be replaced by a String of content that the server sent you. I'm not sure I understand your comment "i have to post it using hash table". Do you mean that you need to put the JSON values into a hashtable object on the device side, after you've parsed the server response?

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.