使用Volley API,我将如何解析此低级JSON以获取此URL

时间:2015-11-03 04:05:12

标签: android json parsing android-volley

我删除了很多不重要的东西来保持这个简单。我只想要url属性。

{
"meta": {
    "status": 200,
    "msg": "OK"
},
"response": {
    "posts": [
        {
            "photos": [
                {
                    "original_size": {
                        "url": "LINK",
                        "width": 612,
                        "height": 612

1 个答案:

答案 0 :(得分:0)

    String json = "...";

    try {
        JSONObject jsonObj = new JSONObject(json);
        JSONObject respObj = jsonObj.getJSONObject("response");
        JSONArray posts = respObj.getJSONArray("posts");
        JSONObject firstPost = (JSONObject) posts.get(0);
        JSONArray photos = firstPost.getJSONArray("photos");
        JSONObject firstPhoto = (JSONObject) photos.get(0);
        JSONObject photoSize = firstPhoto.getJSONObject("original_size");
        String url = photoSize.getString("url");
        Log.e("URL:", url );
    } catch (JSONException e) {
        e.printStackTrace();
    }