【发布时间】:2017-07-20 07:57:51
【问题描述】:
假设我有这本字典
{'person': {'field1': 'text1', 'field2': 'text2'}}
json.dumps 是否可以像这样序列化它
{'person[field1]': 'text1', 'person[field2]': 'text2'}
我知道我可以自己做,但我想问是否有内置方法,因为在 javascript 中有。
【问题讨论】:
-
循环遍历每个人,将新的key person[field1]添加到新的json对象中,并删除旧json中的旧key
-
如果
json.dumps有内置的方法,我会感到非常惊讶,因为它不是标准的序列化方法。 -
"{'person[field1]': 'text1', 'person[field2]': 'text2'}" 不是有效的 json。