JSONデータを取得しています。 GridViewに&表示イメージをダウンロードする際のJSONArrayの使い方どうすればこれを達成できますか?私はDownload and Display Image in Android GridViewを参照します。これはJSONObjectです。parseResult [JSONArray]をパースする方法は?
ここは私のコードです。ここ
private void parseResult(String result) {
try {
JSONObject response = new JSONObject(result);
JSONArray posts = response.optJSONArray("posts");
GridItem item;
for (int i = 0; i < posts.length(); i++) {
JSONObject post = posts.optJSONObject(i);
item = new GridItem();
JSONArray img = post.getJSONArray("img");
if (null != attachments && attachments.length() > 0) {
JSONObject attachment = attachments.getJSONObject(0);
if (img!= null)
item.setImage(img.getString("url"));
}
mGridData.add(item);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
、コードを参照してください。ここで
{
"status": "ok",
"count": 45,
"count_total": 397,
"pages": 9,
"posts": [
{
"id": 12378,
"url": "http://stacktips.com/tutorials/android/speech-to-text-in-android",
},
{...},
{...}
]
}
は
[
{
"id": "95",
"name": "Cherry",
"menu": [
{
"menu_id": "18",
"img": "925dd3ad6d50fa5686a82af26515be5d.jpg"
}
]
},
{...},
{...}
]
ああ、なぜあなたはJSONArrayを使用する必要がありますか? jsonの文字列をjavaオブジェクトにマップしないでください。 –
それを解決するには? – WPG