我希望将对象数组加入到python中的字符串中。有什么办法让我这么做吗?
url = "https://google.com",
search = "thai food",
results = [
{
"restaurant": "Siam Palace",
"rating": "4.5"
},
{
"restaurant": "Bangkok Palace",
"rating": "3.5"
}
]我希望能够将所有这些联系起来,形成一个值。
如果我能让它看起来像:
data = { url = "https://google.com",
{
search = "thai food",
results = [
{
"restaurant": "Siam Palace",
"rating": "4.5"
},
{
"restaurant": "Bangkok Palace",
"rating": "3.5"
}
]
}
}我从mongodb收到这些结果,并希望将这3合并在一起。
发布于 2019-12-06 19:58:08
使用JSON模块
data = {} # create empty dict
# set the fields
data['url'] = 'https://google.com'
data['search'] = 'thai food'
# set the results
data['results'] = results
# export as string
import json
print(json.dumps(data, indent=4)https://stackoverflow.com/questions/59219497
复制相似问题