Java Json对象或字符串中的Json完整响应

Java Json对象或字符串中的Json完整响应,java,json,Java,Json,您好,我正在使用okhttp从服务器获取数据,并通过response.body.string获得响应,该响应正在打印完整数据。但是,当我将响应转换为jsonobject或StringStorage(存储在变量中并打印数据)时,它并没有显示响应的完整数据 "id": 1, "user_id": 1, "first_name": "hhhh", "last_name": "Thakur", 而另一个工作正常 我的json格式数据 { "customers": [ { "id

您好,我正在使用okhttp从服务器获取数据,并通过response.body.string获得响应,该响应正在打印完整数据。但是,当我将响应转换为jsonobject或StringStorage(存储在变量中并打印数据)时,它并没有显示响应的完整数据

"id": 1,
"user_id": 1,
"first_name": "hhhh",
"last_name": "Thakur",
而另一个工作正常 我的json格式数据

{
"customers": [
    {
        "id": 1,
        "user_id": 1,
        "first_name": "hhhh",
        "last_name": "Thakur",
        "website": "",
        "status": 0,
        "created": "2017-10-10T07:29:45+00:00",
        "customer_info": [
            {
                "id": 1,
                "customer_id": 1,
                "created": "2017-10-10T07:29:45+00:00"
            }
        ],
        "customer_address": [
            {
                "id": 1,
                "customer_id": 1,
                "name": "hhhh Thakur",
                "address": "V.PO Chadwal Distt Kathua, Teh Hiranagar  Jammu, Jammu and Kashmir in",
                "city": "Shimla",
                "state": "Himachal Pradesh",
                "zip": "171004",
                "country": "India",
                "fax": "06723",
                "type": 1,
                "as_ship": 1,
                "created": "2017-10-10T07:29:45+00:00"
            },
            {
                "id": 2,
                "customer_id": 1,
                "name": "Neha Sharma",
                "address": "V.PO Chadwal Distt Kathua, Teh Hiranagar  Jammu, Jammu and Kashmir in",
                "city": "India",
                "state": "Jammu and Kashmir",
                "zip": "180012",
                "country": "India",
                "fax": "664984",
                "type": 2,
                "as_ship": 1,
                "created": "2017-10-10T07:29:45+00:00"
            }
        ]
    },
    {
        "id": 2,
        "user_id": 1,
        "first_name": "arun",
        "last_name": "kumar",
        "website": "www.isitwa.com",
        "status": 0,
        "created": "2017-10-11T10:14:38+00:00",
        "customer_info": [
            {
                "id": 2,
                "customer_id": 2,
                "created": "2017-10-11T10:14:38+00:00"
            }
        ],
        "customer_address": [
            {
                "id": 3,
                "customer_id": 2,
                "name": "",
                "address": "",
                "city": "",
                "state": "",
                "zip": "",
                "country": "",
                "fax": "",
                "type": 1,
                "as_ship": 1,
                "created": "2017-10-11T10:14:38+00:00"
            },
            {
                "id": 4,
                "customer_id": 2,
                "name": "",
                "address": "",
                "city": "",
                "state": "",
                "zip": "",
                "country": "",
                "fax": "",
                "type": 2,
                "as_ship": 1,
                "created": "2017-10-11T10:14:38+00:00"
            }
        ]
    }

]}

}这是因为您的JSON无效。。。将您的JSON代码粘贴到此处,它将允许您操作格式化,并更好地查看它

我不是Java方面的专家,但列出嵌套数组不管是JSON还是普通数组,都可以通过两种方式完成:

foreach ( $array as $item) {

    foreach ( $item as $key => $data) {
        echo $data;
    }

}

for ( $i=0; $i < $array.lenght(); $i++ ) {

    for ( $j=0; $j < $array.lenght-1; $j++) {
        print_r $array[$i][$j];
    }
}

如果您不知道数组的长度或嵌套长度,使用foreach方法会更好。

如果json数据格式不正确,请尝试打印以下内容:

{
"a": [
    {
        "id": 1,
        "user_id": 1,
        "first_name": "John",
        "last_name": "",
        "b": [
            {
                "id": 1,
                "customer_id": 1,
                "created": "2017-10-10T07:29:45+00:00"
            }
        ],
        "c": [
            {
                "id": 1,
                "customer_id": 1,
                "created": "2017-10-10T07:29:45+00:00"
            }
        ]
    }],
    "b":[{
        "id": 1,
        "user_id": 1,
        "first_name": "John",
        "last_name": "",
        "b": [
            {
                "id": 1,
                "customer_id": 1,
                "created": "2017-10-10T07:29:45+00:00"
            }
        ],
        "c": [
            {
                "id": 1,
                "customer_id": 1,
                "created": "2017-10-10T07:29:45+00:00"
            }
        ]
    }
]}

这是我的实际json数据如果它能按您的要求工作,请尝试构建类似这样的json id:1,用户id:1,名字:hhhh,姓氏:Thakur,网站:,状态:0,创建时间:2017-10-10T07:29:45+00:00在最后您缺少“}”