我希望有人可以帮助我解决这个问题。我有一个看起来像这样的字符串
a = '[{"name": "bob", "age":"11", "participantid":"Me", "sentiment":"NEUTRAL", "content":"Hey, how you doing."}, {{"name": "Roland", "age":"16", "participantid":"boy", "sentiment":"NEUTRAL", "content":"Hey, I'm doing good and you?."}]'
我的目标是返回列表而不是字符串,所以我期望这样的事情:
a = [{"name": "bob", "age":"11", "participantid":"Me", "sentiment":"NEUTRAL", "content":"Hey, how you doing."}, {{"name": "Roland", "age":"16", "participantid":"boy", "sentiment":"NEUTRAL", "content":"Hey, I'm doing good and you?."}]
我已经坚持了一段时间,使用了replace和stripping,但是没有用。
感谢您的帮助。
答案 0 :(得分:2)
尝试一下:
import json
print(json.loads(a))
或者这个:
import ast
print(ast.literal_eval(a))