json解析错误

{ "symbol": "GOLD", "rates": [{ "time": "2023.08.02 09:00:00", "open": 1948.75000, "high": 1950.30000, "low": 1947.92000, "close": 1949.57000, "tick_volume": 3342, "spread": 0, "real_volume": 0 },{ "time": "2023.08.02 08:00:00", "open": 1946.28000, "high": 1949.90000, "low": 1946.27000, "close": 1948.78000, "tick_volume": 6574, "spread": 0, "real_volume": 0 },{ "time": "2023.08.02 07:00:00", "open": 1949.27000, "high": 1949.28000, "low": 1945.18000, "close": 1946.29000, "tick_volume": 3716, "spread": 0, "real_volume": 0 },{ "time": "2023.08.02 06:00:00", "open": 1948.18000, "high": 1949.44000, "low": 1946.58000, "close": 1949.27000, "tick_volume": 4494, "spread": 0, "real_volume": 0 },{ "time": "2023.08.02 05:00:00", "open": 1947.54000, "high": 1949.80000, "low": 1947.03000, "close": 1948.19000, "tick_volume": 6357, "spread": 0, "real_volume": 0 },{ "time": "2023.08.02 04:00:00", "open": 1949.14000, "high": 1949.79000, "low": 1947.58000, "close": 1947.60000, "tick_volume": 6730, "spread": 0, "real_volume": 0 },{ "time": "2023.08.02 03:00:00", "open": 1952.12000, "high": 1952.35000, "low": 1948.27000, "close": 1949.17000, "tick_volume": 5801, "spread": 0, "real_volume": 0 },{ "time": "2023.08.02 02:00:00", "open": 1951.14000, "high": 1952.80000, "low": 1950.44000, "close": 1952.10000, "tick_volume": 3464, "spread": 0, "real_volume": 0 },{ "time": "2023.08.02 01:00:00", "open": 1947.38000, "high": 1951.78000, "low": 1945.56000, "close": 1951.08000, "tick_volume": 5473, "spread": 0, "real_volume": 0 },{ "time": "2023.08.01 23:00:00", "open": 1944.36000, "high": 1944.82000, "low": 1943.97000, "close": 1944.24000, "tick_volume": 1335, "spread": 0, "real_volume": 0 } ] }

这是我发送到后台的数据,将其命名为data,将上述数据复制到网页上的json解析器可以得到正确的结果。 下面是我的后台代码:

@csrf_exempt
def receive_quotes(request):
    # 获取POST请求中的JSON数据
    src = request.body.decode('utf-8')
    print(src)

    try:
        json_data = json.loads(src)
    except json.JSONDecodeError as e:
        print("Error decoding JSON:", e)

    print(json_data)

    print("**************************************")

    symbol = json_data['symbol']

    print(symbol)

然而当我将数据发送过去后,在loads这里报错Error decoding JSON: Extra data: line 1 column 1694 (char 1693),百思不得其解!!!!!!! 然后为了测试,我写了一个简单的测试:

import json

data=''(这里就是上面发送的数据)
print(data)
data_type=type(data)
data_type_str=str(data_type)
print('The type of data is:'+data_type_str)
print("**************************************")
json_data=json.loads(data)
json_data_type=type(json_data)
json_data_type_str=str(json_data_type)
print('The type of json_data is:'+json_data_type_str)
symbol=json_data['symbol']

print(symbol)

结果发现上述代码可以正确的输出symbol的值是"GOLD",受不了了!!!!!!! 请问各位高手高手高高手,这是什么原因导致的,又该如何解决?

评论 0