为了账号安全,请及时绑定邮箱和手机立即绑定

Python json,不必要的斜杠

Python json,不必要的斜杠

慕丝7291255 2021-04-04 12:55:32
我正在创建一个简单的服务器端应用程序,我使用内置的模块“ json”来创建客户端的答案。if isinstance(obj, (list, tuple)):    return json.dumps({key: [o.to_json() for o in obj if                             isinstance(o, JsonAble)]}, ensure_ascii=False)我的班级在哪里class ArtistSearchResult(JsonAble):    def to_json(self):        return json.dumps({'name': self.name, 'descr': self.descr,                           "url": self.url, 'genres': self.genres},                          allow_nan=False, ensure_ascii=False)它可以工作,但是作为响应,我有一个不必要的斜线:{"responce": ["{\"url\": \"/music/Lindsey+Buckingham\", \"genres\": [\"singer-songwriter\"], \"name\": \"Lindsey Buckingham\", \"descr\": \"Lindsey Adams Buckingham (born October 3, 1949) is an American guitarist, singer, composer and producer, most notable for being the...…read more\"}", "{\"url\": \"/music/Lindsey+Stirling\", \"genres\": [\"violin\"], \"name\": \"Lindsey Stirling\", \"descr\": \"Lindsey Stirling (b. 21 September 1986 in Orange County, California) is a violinist, dancer and composer based in Utah.…read more\"}", "{\"url\": \"/music/Graham+Lindsey\", \"genres\": [\"alt-country\"], \"name\": \"Graham Lindsey\", \"descr\": \"Graham Lindsey is a performing songwriter, an americana singer of subtle, stark ballads and waltzes of love and murder. A member of the...…read more\"}", "{\"url\": \"/music/Lindsey+Haun\", \"genres\": [\"country\"], \"name\": \"Lindsey Haun\", \"descr\": \"Lindsey Haun (born 为什么它们出现在我的答案中?
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 471 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信