0

I got this object using a HttpGet request that I'd like to add to an ArrayList with more objects. What would be the correct way to parse the whole object add it to the array?

{
  "serial_number": "446D57D42F38",
  "name": "Garage Door",
  "accessories": [
    {
      "obfuscated": false,
      "target_state": "closed",
      "current_state": "opening",
      "name": "Garage Door Opener",
      "locked": false
    },
    {
      "hue": 55.5,
      "saturation": 85.5,
      "name": "Light Bulb",
      "power": true,
      "brightness": 95
    }
  ]
}

Code:

List<String> accessories = new ArrayList<String>();

HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
InputStreamReader text = new InputStreamReader(content, "UTF-8");
accessories.add(text.toString())
2
  • why not use jsonarray? and you can use EntityUtils to get the string-json directlty Commented Sep 13, 2014 at 14:41
  • @Nikhil I'm on it, thanks for information! Commented Sep 13, 2014 at 14:47

1 Answer 1

3

Instantiate a JSONArray and then create a for loop. Call the objects inside the jsonarray inside the loop.

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

Comments

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.