【发布时间】:2014-06-30 07:24:24
【问题描述】:
下面的JSONObject格式字符串存储在arraylist ArrayListlatestNews里面;
response.toString() 是
{
"blue": [
{
"title": "http:\\www.b"
},
{
"info": " http:\\www.b"
},
{
"link": "http:\\www.b"
},
{
"image": "http:\\www.b"
},
{
"pubDate": "http:\\www.b"
},
{
"guid": "http:\\www.b"
}
]
}{
"blue": [
{
"title": "http"
},
{
"info": " 5449 1616"
},
{
"link": "http:\\www.b"
},
{
"image": "http:\\www.b"
},
{
"pubDate": "Thu, 26 Jun 2014 16:25:25 GMT"
},
{
"guid": "http:\\www.b"
},
{
"title": "Weekend"
},
{
"info": " 3345 4353"
},
{
"link": "http:\\www.b.."
},
{
"image": "http:\\www.b..."
},
{
"pubDate": "Mon, 23 Jun 2014 09:47:25 GMT"
},
{
"guid": "http:\\www.b"
}
]
}{
"blue": [
{
"title": "KARAVAN "
},
{
"info": " 4444444"
},
{
"link": "http:\\www...."
},
{
"image": "http:\\www...."
},
{
"pubDate": "Thu, 26 Jun 2014 16:25:25 GMT"
},
{
"guid": "http:\\www...."
},
{
"title": "IMC "
},
{
"info": " 134 3333"
},
{
"link": "http:\\www...."
},
{
"image": "http:\\www...."
},
{
"pubDate": "Mon, 23 Jun 2014 09:47:25 GMT"
},
{
"guid": "http:\\www...."
},
{
"title": "property "
},
{
"info": " 633 1352 \ 537 18211"
},
{
"link": "http:\\www....l"
},
{
"image": "http:\\www...."
},
{
"pubDate": "Thu, 26 Jun 2014 16:09:01 GMT"
},
{
"guid": "http:\\www...."
}
....
LatestNews.class
public class LatestNews {
public String title;
public String info;
public String link;
public String image;
public String pubDate;
public String guid;
public LatestNews (String title_,String info_,String link_,String image_,String pubDate_,String guid_){
this.title=title_;
this.info=info_;
this.link=link_;
this.image=image_;
this.pubDate=pubDate_;
this.guid=guid_;
}
}
我正在提取json如下
JSONObject obj = new JSONObject(response.toString());
JSONArray venues = obj.getJSONArray("blue");
System.out.println("response object "+venues.length());
for (int x=0;x<venues.length();x++){
JSONObject keyValue = venues.getJSONObject(x);
if (keyValue.has("title")){
System.out.println("xxxtitle "+keyValue.getString("title"));
}
}
但是当我打印 keyValue.getString("title") 时,只打印第一个标题。如何打印每个蓝色对象中的所有元素,然后将其保存到数组列表中。欢迎任何帮助。
【问题讨论】:
标签: android arraylist jsonobject