将Json数组转换为String

时间:2014-05-21 07:30:13

标签: android json

我有一个PHP的结果作为JSONObject

{"Requests":[{"fromid":"theDude"},{"fromid":"vishaliopeepak@gmail.com"}],"success":1}

我想在 Android 中获取from ids intro String数组?我见过其他例子,但我无法做到正确。

1 个答案:

答案 0 :(得分:0)

试试这个

String response = "{'Requests':[{'fromid':'theDude'},{'fromid':'vishaliopeepak@gmail.com'}],'success':1}";
    JSONObject obj;
    try {
        obj = new JSONObject(response);
        JSONArray jarray = obj.getJSONArray("Requests");
        String success = obj.getString("success");
        if (success.equals("1")) {
            for (int i = 0; i < jarray.length(); i++) {
                JSONObject Jobj = jarray.getJSONObject(i);
                if(Jobj.has("fromid"))
                Log.i("fromid", Jobj.getString("fromid") + "fromid");

            }
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }