我目前正在尝试解析网站上的数据
JSON http://pastebin.com/5DZ5tnTu
xml(我发现这更容易阅读) http://pastebin.com/PPvTEjMv
我正在使用代码
JSONObject jObject = new JSONObject(json);
JSONArray jArray = jObject.getJSONArray("articles");
for (int i=0; i < jArray.length(); i++)
{
try {
JSONObject oneObject = jArray.getJSONObject(i);
String oneObjectsItem = oneObject.getString("title");
String oneObjectsItem2 = oneObject.getString("cps_id");
JSONArray jArray2 = jObject.getJSONArray("articles/image");
JSONObject oneObject2 = jArray2.getJSONObject(0);
String oneObjectsItem3 = oneObject2.getString("src");
Log.i("DATA" ,oneObjectsItem );
Log.i("DATA2" ,oneObjectsItem2 );
Log.i("DATA3" ,oneObjectsItem3 );
} catch (JSONException e) {
Log.e("ERROR", e.getMessage());
我不知道如何获得&#34; src&#34;数据,我尝试将其排序到第二个数组,但/未被识别
答案 0 :(得分:1)
您需要将图像作为对象,然后从中获取src。
JSONObect image = oneObject.getJSONObject("image");
String src = image.getString("src");