PHPで作成したJSON形式のデータをAndroidで読み込んでみる メモ
<?php $json = '{"value":[{"MemberID":"1","Name":"photo1","url":"http://example.com/1.jpg"},'; $json .= '{"MemberID":"2","Name":"photo2","url":"http://example.com/2.jpg"},'; $json .= '{"MemberID":"3","Name":"photo3","url":"http://example.com/3.jpg"}]}'; print($json); //print(json_encode($json));//使わない ?>
private void json_parse(String jsondata){ try { JSONObject jsonResponse = new JSONObject(jsondata); JSONArray data = jsonResponse.getJSONArray("value"); for(int i = 0; i < data.length(); i++){ JSONObject c = data.getJSONObject(i); Log.d("ID",c.getString("MemberID")); Log.d("NAME",c.getString("Name")); Log.d("URL",c.getString("url")); } } catch (JSONException e) { e.printStackTrace(); } }