JSON 中的意外标记 {

Unexpected token { in JSON

你好,我正在使用 Elastic Search 和 Golang,当我使用 Golang 的 Json 编码器功能将数据发送到 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}}

您似乎在尝试发送 2 个单独的 JSON,但没有任何类型的连接器。 尝试将整个内容包装在 {} 中,并在 {"id": 213.

之前加上一个逗号

您的 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/