如何从json中找到“imagepath”的值

时间:2014-03-22 08:50:43

标签: android json

{
    "rank": "-text_relevance",
    "match-expr": "(label 'ifrs')",
    "hits": {
        "found": 14,
        "start": 0,
        "hit": [
            {
                "id": "m9749",
                "data": {
                    "actionurl": [
                        "http://ias-/hjhjk"
                    ],
                    "description": [
                        "IFRS 3 Business Combinations  The objective of the IFRS is to enhance the relevance, reliability and"
                    ],
                    "educator": [
                        " Pvt. Ltd"
                    ],
                    "featured": [
                        "N"
                    ],
                    "imagepath": [
                        "http://WMHCEEHTM/bookstore/14828384_15351162_96526729_P.jpg"
                    ],
                    "rating": [],
                    "text_relevance": [
                        "690"
                    ],
                    "title": [
                        "IAS 27, IFRS 3, IAS 28, IAS 31 Consolidation Part II"
                    ],
                    "topic": [
                        "Accounting",
                        "Banking / Finance / Accounts",
                        "Skill Development & Professional"
                    ],
                    "type": [
                        "MODULE"
                    ]
                }
            }
        ]
    },
    "info": {
        "rid": "6cab70a42101dc6625e2eaea1a18f5b88388923b0fc31965ecd3b9820036dab0b77d928ca7a50a49",
        "time-ms": 4,
        "cpu-time-ms": 4
    }
}

2 个答案:

答案 0 :(得分:1)

试试这个..

JSONObject json = new JSONObject(response);

JSONObject hits = json.getJSONObject("hits");
JSONArray hit_array = hits.getJSONArray("hit");

for(int i = 0; i < hit_array.lenght(); i++){
       JSONObject obj = hit_array.getJSONObject(i);
       JSONObject data = obj.getJSONObject("data");
       JSONArray imagepath_array = data.getJSONArray("imagepath");

       for(int j = 0; j < imagepath_array.lenght(); j++)
             String imagepath_url = imagepath_array.getString(j);
}

答案 1 :(得分:0)

猜猜你在谈论用Java保存/访问JSON格式。您可以使用像Gson这样的库来将响应解析为JsonArray,就像这样,

JsonArray yourObj = new JsonParser()
                          .parse(your_json_string)
                          .getAsJsonObject();
// Access your object like so - yourObj.get("hits").getAsJsonObject().get("hit").getAsJsonArray();
// loop through the array, to get each object, in that object get property

Gson图书馆链接 - https://code.google.com/p/google-gson/

这有帮助吗?