Python 如何从该字符串格式中提取此字段?

Python 如何从该字符串格式中提取此字段?,python,regex,Python,Regex,如何使用正则表达式或python代码从该字符串中提取“MP3:not support” 但根据建议产生了一个错误: [{"answerInfo":{"extraData":{"am_answer_type":"NN"}},"content":"MP3:not support.","messageId":"c4d6a2f4649d483a811fcce4b26ae9a1"}] 回溯(最近一次呼叫最后一次): 文件“/Users/congminmin/PycharmProjects/Misc/cs

如何使用正则表达式或python代码从该字符串中提取“MP3:not support”

但根据建议产生了一个错误:

[{"answerInfo":{"extraData":{"am_answer_type":"NN"}},"content":"MP3:not support.","messageId":"c4d6a2f4649d483a811fcce4b26ae9a1"}]
回溯(最近一次呼叫最后一次):
文件“/Users/congminmin/PycharmProjects/Misc/csv/csvLoader.py”,第16行,在
打印(问题+“”+json.loads(答案)[0]['content'])
文件“/Users/congminmin/anaconda3/lib/python3.6/json/_init__.py”,第354行,加载
返回\u默认\u解码器。解码
文件“/Users/congminmin/anaconda3/lib/python3.6/json/decoder.py”,第339行,在decode中
obj,end=self.raw\u decode(s,idx=\u w(s,0.end())
文件“/Users/congminmin/anaconda3/lib/python3.6/json/decoder.py”,第357行,原始解码
从None引发JSONDecodeError(“预期值”,s,err.value)
json.decoder.JSONDecodeError:预期值:第1行第1列(字符0)

根据您的示例,我建议使用
json
而不是
regex

检查一下


如果在您的str中(“MP3:not support”)打印'yay'@user697911,我为您添加了一个链接,以便您能够看到它运行,我相信您可能有一些特殊的字符和编码导致了错误
Traceback (most recent call last):
  File "/Users/congminmin/PycharmProjects/Misc/csv/csvLoader.py", line 16, in <module>
    print(question+ " " + json.loads(answer)[0]['content'])
  File "/Users/congminmin/anaconda3/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/Users/congminmin/anaconda3/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Users/congminmin/anaconda3/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Python 3.6.5 (default, Jun 17 2018, 12:13:06)
>>> text = '[{"answerInfo":{"extraData":{"am_answer_type":"NN"}},"content":"MP3:not support.","messageId":"c4d6a2f4649d483a811fcce4b26ae9a1"}]'
>>> import json
>>> json.loads(text)[0]['content']
'MP3:not support.'
import json

json_data = '[{"answerInfo":{"extraData":{"am_answer_type":"NN"}},"content":"MP3:not support.","messageId":"c4d6a2f4649d483a811fcce4b26ae9a1"}]'

python_obj = json.loads(json_data)
print(python_obj[0]["content"])