Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.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
Android 从jsonobject检索arraylist_Android_Json_Arraylist - Fatal编程技术网

Android 从jsonobject检索arraylist

Android 从jsonobject检索arraylist,android,json,arraylist,Android,Json,Arraylist,我是android新手,需要帮助从JSONObject检索ArrayList并向其中添加元素。我有一个json对象X,其形式为{'a':[],'b':[],…}。其中,[]表示我已定义的“B”的数组列表。我想在X中的ArrayList之一中添加一个元素 我已经做了: B temp = new B(); x.get("string").add(B) 这就是错误: (176,31)错误:不兼容的类型 必需:ArrayList 发现:对象 谢谢 无法从JSON检索数组列表,因为JSON是一种人类可读

我是android新手,需要帮助从
JSONObject
检索
ArrayList
并向其中添加元素。我有一个json对象X,其形式为
{'a':[],'b':[],…}
。其中,
[]
表示我已定义的“B”的
数组列表。我想在X中的
ArrayList
之一中添加一个元素

我已经做了:

B temp = new B();
x.get("string").add(B)
这就是错误:

(176,31)错误:不兼容的类型 必需:ArrayList 发现:对象


谢谢

无法从JSON检索数组列表,因为JSON是一种人类可读的数据类型。您可以这样做:

ArrayList<B> list = new ArrayList();
B b= new B();
b.setB(x.getString("Key"));
list.add(b);

b.set("");  is a method could be in your class to set the value of B
x.getString(""); is for getting String type value from the JSON on a specified key
ArrayList list=new ArrayList();
B=新的B();
b、 setB(x.getString(“Key”);
列表.添加(b);
b、 集合(“”);是一个可以在类中设置B值的方法
x、 getString(“”);用于从指定键上的JSON获取字符串类型值

这个东西被称为Json数组,而不是ArrayList那么B的数组和JSONarray一样吗@Vivekno如何在androidSo中解析json响应与普通的ArrayString搜索不同。存储多个ArrayList的最佳方法是什么@术士,谢谢@SaaRAM是什么意思?多个数组,你可以举一个例子来考虑帖子和评论作为例子。每个帖子都有一组独特的评论。因此,一个ARARYLIST包含一个特定帖子的评论,而这个关键词是帖子的ID。