Q
如何使用畢加索
0
A
回答
0
請嘗試以下
try {
JSONObject jsonFeed = new JSONObject(your_original_json).getJSONObject("feed");
JSONArray entries = jsonFeed.getJSONArray("entry");
int count = entries.length();
for (int i = 0; i < count; i++) {
JSONObject imageJson = entries.getJSONObject(i).getJSONObject("im:image");
// in case you want to get image with height 53
String imageUrl = imageJson.getJSONObject("0").getString("label");
// String imageUrl = imageJson.getJSONObject("1").getString("label"); height 75
// String imageUrl = imageJson.getJSONObject("2").getString("label"); height 100
Picasso.with(context)
.load(imageUrl)
.into(imageView);
}
} catch (JSONException e) {
e.printStackTrace();
}
0
你必須使用的HttpClient從您的網址獲得JSON。下面的代碼。
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://itunes.apple.com/jo/rss/topfreeapplications/limit=50/json");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream weps = entity.getContent();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(weps, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
weps.close();
result = sb.toString();//result string defined above will store your json.
} catch (Exception e) {
Log.e("log_tag", "Error Coverting result" + e.toString());
}
} catch (Exception e) {
Log.e("log_tag", "Error Http connection" + e.toString());
}
try {
JSONArray entries = new JSONArray(result);
int count = entries.length();
for (int i = 0; i < count; i++) {
JSONObject imageJson= entries.getJSONObject(i).getJSONObject("im:image");
// in case you want to get image with height 53
String imageUrl = imageJson.getJSONObject("0").getString("label");
// String imageUrl = imageJson.getJSONObject("1").getString("label"); height 75
// String imageUrl = imageJson.getJSONObject("2").getString("label"); height 100
Picasso.with(context)//context variable of the class
.load(imageUrl)// url from Json
.into(imageView); //your image view object
}
} catch (Exception e) {
Log.e("log_tag", "Error Parsing Dataaaa" + e.toString());
}
+0
謝謝你的回答,但我如何在這裏使用它? [鏈接](http://stackoverflow.com/questions/39406698/parsing-data-from-json-as-a-collection-of-image-to-picasso/39406947?noredirect=1#comment66139330_39406947) –
相關問題
- 1. 如何使用畢加索
- 2. :使用畢加索
- 3. 使用畢加索
- 4. 如何使用畢加索從InputStream中
- 5. 的Android使用畢加索
- 6. 如何使用畢加索加載動畫列表?
- 7. 如何加載JPEG作爲使用畢加索
- 8. 問題用畢加索
- 9. 使用縮略圖作爲畢加索
- 10. 使用畢加索的OutOfMemoryException問題
- 11. 使用Recyclerview實現畢加索
- 12. 爲什麼畢加索不使用imageView.getContext()?
- 13. 使用帶有RoundedBitmapDrawable的畢加索
- 14. 如何通過上下文畢加索
- 15. 畢加索不加載ArrayAdapter
- 16. 如何使用畢加索保存和顯示圖像
- 17. 如何使用畢加索從mp3文件設置圖像
- 18. 如何下載和使用畢加索庫
- 19. 如何使用帶有MediaStore的畢加索圖書館
- 20. 如何顯示,而無需使用Android的畢加索
- 21. 如何使用畢加索加載favicon.ico的圖標在Android應用
- 22. 使畢加索的緩存無效
- 23. 畢加索和Firebase存儲
- 24. 畢加索vs壁畫
- 25. 畢加索生產OutOfMemoryError
- 26. 畢加索和ImageLoader android
- 27. 畢加索重複圖像
- 28. 畢加索緩存例外
- 29. 畢加索圖像緩存
- 30. IssuePager by usng畢加索
我在這裏澄清,我的問題[鏈接](http://stackoverflow.com/questions/39429158/parsing-jsonarray-to-picasso-library) 如果你不會回答我! –