猿问

Python json,不必要的斜杠

我正在创建一个简单的服务器端应用程序,我使用内置的模块“ 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 

为什么它们出现在我的答案中?


慕丝7291255
浏览 472回答 2
2回答
随时随地看视频慕课网APP

相关分类

Python
我要回答