提高JSON解码错误的期望值:第1行第1列(字符0)

我正在使用Django创建网站。 下面是我的代码:

views.py:

for i in range(0,len(userdata)):
        json_hall = requests.get(
            "https://www.onebookingsystem.com/API/Admin/booking_list_id.php?id=%s" % userdata[i]['bookid'])
        r = json_hall.json()
        hall_data = json.loads(json_hall.text)
        id_data[i]['bookid'] = hall_data[0]['bookid']

当我运行时,我得到这样的错误。

File "D:\KarthikWorkSpace\Projects\Python\obs_admin\Application\obs_app\views.py", line 1968, in bookings_owner
hall_data = json.loads(json_hall.text)

raise JSONDecodeError("Expecting value", s, err.value) from None

json.decoder.JSONDecodeError:预期值:第1行第1列(字符0)

任何帮助,将不胜感激。

评论
  • caut
    caut 回复

    When using requests, the .json() method on a response object already gives you a Python object (decoded from the literal response)

    You don't need to parse again the data with json.loads. By the way, here's a more Pythonic way to iterate over your data:

    for (idx, user) in enumerate(userdata):
        response = requests.get(
                "https://www.onebookingsystem.com/API/Admin/booking_list_id.php?id=%s" % user['bookid'])
        hall_data = response.json()
        id_data[idx]['bookid'] = hall_data[0]['bookid']