String转Array

来源:互联网 发布:linux 改sftp 22端口 编辑:程序博客网 时间:2024/06/05 14:18

获取到http响应         

//获取响应

        String responseStr = response.get("body");

        System.out.println("responseStr:" + responseStr.toString());

//responseStr: [{"name":"Tom","age":"25"},{"name":"Marry","age":"18"}]


解析该String  用ArrayList,Array是不行的

需要用JSONObject  如下

JSONArray responseJson = JSONObject.parseArray(responseStr);

//解析

        System.out.println("responseJson:" + responseJson.getString(0));
        int i = 0;
        for (Object json : responseJson) {
            i++;
            System.out.println(i + ":" + json.toString());
        }

原创粉丝点击