0
{"Result": {
    "version": [
      "001","002","003","004","005"
    ],
 "Names": {
      "001": "NoName","002": "NoName","003": "Cupcake","004": "Donut","005": "Eclair"
    }
}}

上面显示的结果是我现在作为响应得到的结果,我如何从上面检索相应的名称。请。任何人都可以帮助我解决这个问题。谢谢

4

2 回答 2

2

请参考这个Android Json 解析示例

你可以像下面这样可以帮助你。

JSONObject mjsonObject = null;
        try {
            mjsonObject=new JSONObject(jsonString);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        JSONArray mjsonArray;

        JSONObject mJsonObject2,jsonObjectNames;
        try{
            mJsonObject2= mjsonObject.getJSONObject("Result");
            mjsonArray=mJsonObject2.getJSONArray("version");
            jsonObjectNames=mJsonObject2.getJSONObject("Names");

            String[] versionName=new String[mjsonArray.length()];
            for(int i=0;i<mjsonArray.length();i++){
                if(!mjsonArray.isNull(i)){
                    versionName[i]=mjsonArray.getString(i);
                }
            }
            String [] versionString=new String[mjsonArray.length()];



        }catch(JSONException json){
            json.printStackTrace();
        }catch(NullPointerException excep){

        }
于 2012-05-16T09:08:10.020 回答
0

海参考这个你会得到一个想法

    try {
        resp = new JSONObject(shared);
        cities = new JSONArray(resp.getString("cities"));

        for (int i = 0; i < cities.length(); i++) {

            JSONObject jsonObject = cities.getJSONObject(i);
            id = jsonObject.getString("id");

            operators = jsonObject.getJSONArray("operators");

            if (id.equalsIgnoreCase(String.valueOf(srcid1))) {

                for (int j = 0; j < operators.length(); j++) {
                    JSONObject jsonObject1 = operators.getJSONObject(j);
                    oid = jsonObject1.getString("id");

                    vehicle = jsonObject1.getJSONArray("vehicles");

                    if (oid.equalsIgnoreCase(value)) {
                        Log.v("json", "msg");
                        for (int k = 0; k < vehicle.length(); k++) {

                            jsonObject2 = vehicle.getJSONObject(k);
                            vehiclename = jsonObject2.getString("name");
                            id = jsonObject2.getString("id");
                            int vehicleid = Integer.parseInt(id);
                            map = new HashMap<String, String>();
                            Log.v("vehi", "" + vehiclename);
                            Log.v("vehi", "" + vehicleid);
                            map.put("id", "" + id);
                            map.put("vehiclename", "" + vehiclename);
                            mylist.add(map);
                            Log.v("count", "" + mylist.toString());

                        }

                    }

                }

            }

        }
于 2012-05-16T09:32:35.877 回答