问题描述
- android JSON的解析器
-
我从android Http中获取一个长字符串,如下:{"movies":[ {"movieId":"fmen71229238","eTitle":"Mission: Impossible - Ghost Protocol","cTitle":"不可能的任務:鬼影行動","imageUrl":"http://test.mobibon.com.tw/MovieGoTest/Pics/pl_fmen7122923814_s.jpg","releaseDate":"2011/12/15","saleType":"0"}, {"movieId":"fstw79905171","eTitle":"Seediq Bale","cTitle":"賽德克.巴萊(上)太陽旗","imageUrl":"http://test.mobibon.com.tw/MovieGoTest/Pics/pl_fstw7990517114_s.jpg","releaseDate":"2011/9/9","saleType":"0"}, {"movieId":"fytw91390391","eTitle":"You Are the Apple of My Eye","cTitle":"那些年,我們一起追的女孩","imageUrl":"http://test.mobibon.com.tw/MovieGoTest/Pics/pl_fytw9139039102_s.jpg","releaseDate":"2011/8/19","saleType":"0"} ]}
字符串是JSON格式,我想让它在不同的数组中排列,再在一个Listview中显示。所以我使用JSON paser:
JSONArray result = new JSONArray(retSrc); for(int i = 0;i < result.length(); i++) { JSONObject stock_data = result.getJSONObject(i); Log.i("bird","eTitle:"+stock_data.getString("eTitle")); } } finally { } }
retSrc 是网站的长字符串
但是Log是:Log.i("bird","eTitle:"+stock_data.getString("eTitle"));
没有输出任何东西.
我希望log是这样的:
Mission: Impossible - Ghost Protocol Seediq Bale.....
解决方案
JSONObject jObj=new JSONObject(retSrc);
JSONArray jArr=jObj.getJSONArray("movies");
for(int i = 0;i < result.length(); i++)
{
JSONObject stock_data = result.getJSONObject(i);
}
解决方案二:
你先这样做了吗?:
JSONObject retSrc= 你获得的json的str.getJSONObject("movies");
时间: 2024-12-30 13:55:54