Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将整个JSON对象添加到ArrayList_Java_Android_Json_Arraylist - Fatal编程技术网

Java 将整个JSON对象添加到ArrayList

Java 将整个JSON对象添加到ArrayList,java,android,json,arraylist,Java,Android,Json,Arraylist,我使用一个HttpGet请求获得了这个对象,我想将它添加到一个包含更多对象的ArrayList中。解析整个对象并将其添加到数组中的正确方法是什么 { "serial_number": "446D57D42F38", "name": "Garage Door", "accessories": [ { "obfuscated": false, "target_state": "closed", "current_state": "opening

我使用一个HttpGet请求获得了这个对象,我想将它添加到一个包含更多对象的ArrayList中。解析整个对象并将其添加到数组中的正确方法是什么

{
  "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
    }
  ]
}
代码:

列出附件=新的ArrayList();
HttpResponse response=client.execute(httpGet);
HttpEntity=response.getEntity();
InputStream内容=entity.getContent();
InputStreamReader文本=新的InputStreamReader(内容,“UTF-8”);
附件。添加(text.toString())

实例化JSONArray,然后创建for循环。在循环内调用jsonarray内的对象。

实例化jsonarray,然后创建for循环。在循环内调用jsonarray内的对象。

实例化jsonarray,然后创建for循环。在循环内调用jsonarray内的对象。

实例化jsonarray,然后创建for循环。在循环中调用jsonarray中的对象。

为什么不使用jsonarray?您可以使用EntityUtils获取字符串jsondirectlty@Nikhil我会的,谢谢你的信息!为什么不使用jsonarray呢?您可以使用EntityUtils获取字符串jsondirectlty@Nikhil我会的,谢谢你的信息!为什么不使用jsonarray呢?您可以使用EntityUtils获取字符串jsondirectlty@Nikhil我会的,谢谢你的信息!为什么不使用jsonarray呢?您可以使用EntityUtils获取字符串jsondirectlty@Nikhil我会的,谢谢你的信息!
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())