大家好,我刚刚开始学习python。我决定制作一个发送随机笑话的 tg 机器人。我从开源中获取了 API,页面通过浏览器打开(http://rzhunemogu.ru/RandJSON.aspx?CType=1)。错误 json.decoder.JSONDecodeError: 无效控制字符:第 1 行第 73 列(字符 72),据我了解,网站本身的某些字符是否有问题?预先感谢您的帮助。
import telebot
import requests
import json
bot = telebot.TeleBot('?????')
@bot.message_handler(commands=['start'])
def start(message):
bot.reply_to(message, "This joke for you")
joke = requests.get('http://rzhunemogu.ru/RandJSON.aspx?CType=1')
jsonjoke = json.loads(joke.text)
bot.send_message(message.chat.id, jsonjoke)
bot.polling()
该站点
http://rzhunemogu.ru/RandJSON.aspx?CType=1发送曲线 JSON。此代码将帮助您删除多余的字符