从 JSON 响应中获取一个字符串并将其加 1

Getting a string from JSON response and adding 1 to it

我有一个来自票务系统的 RESTful GET 请求。它获取系统中输入的最新票号,并为用户打印。然后我需要做的是获取它给出的数字,然后为 POST 请求加一。例如,这是我的代码:

response = requests.get(url=url, headers=headers)
    data2 = response.json()
    ntickId = data2[0]['id']
    if tickId < ntickId:
        pprint(f"The most recent ticket is: {ntickId}. Press any key to continue.")
        input(" ")
        pprint(f"Your new ticket number will be: " + int({ntickId})+1)

之前,我输入了数字 468516。这是我的输出:

Please Enter Event Ticket ID: 468516
'The most recent ticket is: 468999. Press any key to continue.

到目前为止一切顺利。因此,理想情况下 我希望 469000 成为新的票号。这是我得到的:

pprint(f"Your new ticket number will be: " + int({ntickId})+1)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'set'

我不知道该怎么做。

应该是:

pprint(f"Your new ticket number will be: {int(ntickId)+1}")

请注意,鉴于您比较了 tickIdntickId 转换为 int 很可能没有必要,因为 ntickId 已经是一个 int。您可以编辑您的问题以包含来自 API 的样本 JSON 回复。在这种情况下:

pprint(f"Your new ticket number will be: {ntickId+1}")