-1

How to parse json output using java with below scenorio.

I have json result (output) in getDetails() below is the json output for getDetails()

[{"myInfo":[{"name":"surya","mobile":"7893939393"}],"status":"active"}]    

How I can return the 'mobile' value using java

1 Answers1

2

Regarding the Json syntax you miss in the end }] symbols. I use JsonArray because of your example. I am using org.json.JSONArray;

String json = "[{\"myInfo\":[{\"name\":\"surya\",\"mobile\":\"7893939393\"}]}]";

    JSONArray jsonArray = new JSONArray(json);
    System.out.println(jsonArray.getJSONObject(0)
                    .getJSONArray("myInfo")
                    .getJSONObject(0)
                    .get("mobile"));
Echoinacup
  • 482
  • 4
  • 12
  • List json = instance.getNetworkInterfaces(); i have result in avobe method. Getting error when i have implemented as you suggested. error: The constructor JSONArray(List) is undefined The method getJSONObject(int) is undefined for the type JSONArray – user2185115 Jan 09 '19 at 07:35
  • Got the solution. Thanks – user2185115 Jan 09 '19 at 10:24