如何组合键text
的两个值并在其间返回“\ n”键?我希望输出显示如下。
{ "text": "Hi ! Nice to meet you !\nMy name is Robot." }
这是JSON结构:
{
"output": {
"log_messages": [],
"text": [
"Hi ! Nice to meet you !",
"My name is Robot."
],
"nodes_visited": [
"Hello"
]
}
我想出了如何返回两个键,但不知道如何将它们作为一个字符串返回。谢谢!
答案 0 :(得分:2)
with open(filename) as f:
obj = json.load(f)
output = {'text': '\n'.join(obj['output']['text'])}
print output
# {'text': 'Hi ! Nice to meet you !\nMy name is Robot.'}