【问题标题】:Convert Json array intro String [duplicate]将Json数组转换为字符串[重复]
【发布时间】:2014-05-21 07:30:12
【问题描述】:

我有一个来自 PHP 作为 JSONObject 的结果

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

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

【问题讨论】:

  • 响应二维数组如何
  • 好的,我在另一篇帖子here 中找到了答案。但我无法删除这个问题
  • 这可能是因为您已接受答案
  • 我取消标记并尝试过,但仍然无法正常工作

标签: android json


【解决方案1】:

试试这个

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();
    }

【讨论】:

    猜你喜欢
    • 2014-07-11
    • 1970-01-01
    • 1970-01-01
    • 2018-12-17
    • 1970-01-01
    • 2014-01-23
    • 1970-01-01
    • 2013-12-05
    • 1970-01-01
    相关资源
    最近更新 更多