解析字典中的文本

问题描述 投票:1回答:1

我有一本包含以下文字的字典:

{
        "body": "Customer: \"I have a big problem. You cut off my head!\"\r\n\r\nMe: \"I'm sorry? How did I cut off your head?\"\r\n\r\n(The customer shows me an obviously self-taken picture, with the top of his head removed.)\r\n\r\nMe: \"Sir, it looks like it was taken that way.\"\r\n\r\nCustomer: \"No it wasn't! My whole head was there when I took it. I'm sure!\"\r\n\r\nMe: \"Okay, let me see your memory card...\"\r\n\r\n(The customer hands it to me, and I go in the lab and pull it up on the computer. Sure enough, he chopped his own head off in the picture.)\r\n\r\nMe: \"Sir, that is the whole image, and the top of your head isn't in it.\"\r\n\r\nCustomer: \"But it's DIGITAL, can't you fix it?\"\r\n\r\nMe: \"You can't create something from nothing.\"\r\n\r\nCustomer: \"But... but... but... I need a photo for a dating website!\"\r\n\r\nMe: \"Give me the camera and go stand over there.\"\r\n\r\nCustomer: *excited* \"Hot d***! You can be my best man!\"\r\n\r\nMe: \"A thank you card will be enough.\"\r\n\r\n(Skip ahead 9 months...)\r\n\r\nFemale customer: \"Is your name ***?\"\r\n\r\nMe: \"Yes, can I help you?\"\r\n\r\nFemale customer: \"My husband wanted you to have this.\" *hands me an envelope*\r\n\r\n(I open the envelope, and sure enough there's a thank you card with a picture of him and his wife. He actually got married and sent her in with the card!)",
        "category": "Men / Women",
        "id": 18189,
        "title": "A Heady Proposition"
    },

但是我完全不确定如何解析body的文本,以便可以从上方获取可读的文本。

我正在寻找一种通用的解决方案,而不是根据CustomerMe之类的关键字进行解析>

文本应如下图所示:enter image description here

我有一本字典,上面有以下文字:{“ body”:“ Customer:\”我有一个大问题。你砍了我的头!\“ \ r \ n \ r \ n我:\”对不起?我是怎么砍掉你的头的?\“ \ r \ n \ r \ n(客户...

python-3.5 string-parsing
1个回答
0
投票

您可以按定界符样式\r\n\r\n+进行拆分

© www.soinside.com 2019 - 2024. All rights reserved.