0

I have simple response from a page in JSON format which looks like this:

{"ip": "89.164.255.124"}

This is a trivial example from http://ip.jsontest.com/ that I am using only to learn how to do it.

I need to serialize that response into array and then then run a loop to show it in a table. This needs to be done in Java.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264

2 Answers2

0

try this code :

public class Test {
public static void main(String[] args) throws ParseException {
    JSONObject json = new JSONObject("{ 'ips': [ { 'ip': '192.168.0.1' }, { 'ip': '192.168.0.2' }, { 'ip': '192.168.0.3' } ]}");
    JSONArray jsonArray = json.getJSONArray("ips");
    for (int i = 0; i < jsonArray.length(); i++) {
        System.out.println(jsonArray.getJSONObject(i).get("ip"));
    }
}

}

Ref :

Nitin
  • 2,701
  • 2
  • 30
  • 60
0

I always use GWT Jackson.

I found it much clearer how to use than working with JSONObject, JSONArray and stuff like that.

Knarf
  • 2,077
  • 1
  • 16
  • 24