2017-06-26 34 views
0

extra_images: { URL: 「.PNG」 },{ URL: 「 .PNG」 },{ URL : 「* .png格式」 } ]如何在android或getdata中解析JSON並將其轉換爲其他活動?

JSONArray extra_images = details.getJSONObject(i).getJSONArray("extra_images"); 

for (int m = 0; m < extra_images.length(); m++) { 
    url = extra_images.getJSONObject(m).getString("url"); 
} 
+0

,你所面臨的問題是什麼檢索數據? – Ezio

+0

這種類型的JSONArray不能用於其他活動?這個怎麼做? –

+0

i.putStringArrayListExtra(「urlList」,requestdataArrayList.get(position).get(「urlList」));它不是okeay ... so –

回答

0

要將數據用於意向使用intent.putExtra,要解析JSON,根據需要使用類JSONObjectJSONArray來檢索內部數據使用意向函數intent.get*Extra

+0

i.putStringArrayListExtra(「ulist」,** requestdata.get(position).get(「url」)**);仍然錯誤裏面的粗體他們的錯誤:字符串不能轉換ArrayList 我需要他們轉換....我們如何處理這個 –

+0

你寫的方式太少的代碼,我不明白 – Seaskyways

+0

JSONArray extra_images = details.getJSONObject (ⅰ).getJSONArray( 「extra_images」); (int m = 0; m

0

做這個

ArrayList<String> urlList = new ArrayList<>(); 
JSONArray extra_images = details.getJSONObject(i).getJSONArray("extra_images"); 

for (int m = 0; m < extra_images.length(); m++) { 
    urlList.add(extra_images.getJSONObject(m).getString("url")); 
} 

//declare your intent here 
intent.putStringArrayListExtra("intent_key",urlList); 

然後在你的目標活動,使用

ArrayList<String> urlList = getIntent().getStringArrayListExtra("intent_key"); 
相關問題