如何从Android的访问内部数组的JSON数组 [英] how to access the json array inside array from android

查看:230
本文介绍了如何从Android的访问内部数组的JSON数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的阵列

  {
   newsitem [
              {标题:你好,说明:日期                  形象:{照片:IMG,拇指:缩略图}
             }
            ]
}

我想用的JSONObject和jsonarray访问照片和拇指。我能够访问标题和标题。

这是code,我用得到的标题。帮我拿到照片和拇指。

 的JSONObject的obj =新的JSONObject(retstring);
                JSONArray JA = obj.getJSONArray(NewsItem);的for(int i = 0; I< ja.length();我++){                    JSONObject的乔=(JSONObject的)ja.get(I)
串H = jo.getString(标题);}


解决方案

您可以试试下面的示例:

 的JSONObject new_jo = jo.getJSONObject(图像);
  字符串PIC = new_jo.getString(照片);
  字符串缩略图= new_jo.getString(拇指);

my array is

{
   newsitem [ 
              {"headline":"hello","caption":"date",

                  "image":{"photo":"img","thumb":"thumbnail"}
             }
            ]
}

I want to access photo and thumb using jsonobject and jsonarray. I am able to access headline and caption.

this is the code I am using to get headline. help me to get photo and thumb.

JSONObject obj = new JSONObject(retstring);
                JSONArray ja = obj.getJSONArray("NewsItem"); 

for (int i = 0; i < ja.length(); i++) {

                    JSONObject jo = (JSONObject) ja.get(i);


String h=jo.getString("HeadLine");

}

解决方案

You can try sample below :

  JSONObject new_jo = jo.getJSONObject("image");
  String pic = new_jo.getString("photo");
  String thumbnail = new_jo.getString("thumb");

这篇关于如何从Android的访问内部数组的JSON数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆