-1

您好,我正在使用 Elastic Search 和 Golang,当我使用 Golang 的 Json Encoder 函数将数据发送到 jquery 时,从 Golang 中的弹性搜索索引获取数据后,我"Unexpected token { in JSON "在解析 jquery 中的数据时出错

这是 Goland Json 编码器发送给 Jquery 的内容:

{"id":212,"user_id":10,"meta_description":"Plot,G-16, Islamabad,In G-16, Islamabad, Islamabad","property_type":"16","Location1":"Pakistan","Location2":"Islamabad","Location3":null,"Location4":"Islamabad","price":1850000,"bedrooms":0,"bathrooms":0,"add_date":{"Time":"0001-01-01T00:00:00Z","Valid":false}}
{"id":213,"user_id":10,"meta_description":"Plot,G-16, Islamabad,In G-16, Islamabad, Islamabad","property_type":"16","Location1":"Pakistan","Location2":"Islamabad","Location3":null,"Location4":"Islamabad","price":1800000,"bedrooms":0,"bathrooms":0,"add_date":{"Time":"0001-01-01T00:00:00Z","Valid":false}}
4

2 回答 2

1

您的 JSON 数据缺少两件重要的事情,一是将其封装在方括号中,并将','每个数据封装为分隔符。或多或少应该是这样的:

[{
    "id": 212,
    "user_id": 10,
    "meta_description": "Plot,G-16, Islamabad,In G-16, Islamabad, Islamabad",
    "property_type": "16",
    "Location1": "Pakistan",
    "Location2": "Islamabad",
    "Location3": null,
    "Location4": "Islamabad",
    "price": 1850000,
    "bedrooms": 0,
    "bathrooms": 0,
    "add_date": {
        "Time": "0001-01-01T00:00:00Z",
        "Valid": false
    }
}, {
    "id": 213,
    "user_id": 10,
    "meta_description": "Plot,G-16, Islamabad,In G-16, Islamabad, Islamabad",
    "property_type": "16",
    "Location1": "Pakistan",
    "Location2": "Islamabad",
    "Location3": null,
    "Location4": "Islamabad",
    "price": 1800000,
    "bedrooms": 0,
    "bathrooms": 0,
    "add_date": {
        "Time": "0001-01-01T00:00:00Z",
        "Valid": false
    }
}]

我做了很小的改变,如果您不确定数据,最好的选择是尝试在这里验证它:https ://jsonlint.com/

于 2018-05-18T06:13:15.273 回答
0

看起来您正在尝试发送 2 个没有任何连接器的单独 JSON。尝试将整个内容包装在 { } 中,并在 {"id": 213 之前放置一个逗号。

于 2018-05-18T05:23:49.330 回答