【发布时间】:2020-07-23 18:24:26
【问题描述】:
print(keystr)
print(addstr10)
dict[keystr] = addstr10
json.dump(dict, json_file, indent=2)
这会产生 keystr = nested_object 对于 addstr10 它产生
{"another_nested_object": { "another_another_nested_object": "ymwjkxpr", "integervalue" : 11, "floatvalue" : 4.703165912962773, "anothernamer" : True, "another_nested_object_1": { "another_key": "vbiofdhz" } } }
看起来不错,但 json 文件在值对中有额外的反斜杠,我想去掉它
{
"nested_object": "{\"another_nested_object\": { \"another_another_nested_object\": \"ymwjkxpr\", \"integervalue\" : 11, \"floatvalue\" : 4.703165912962773, \"anothernamer\" : True, \"another_nested_object_1\": { \"another_key\": \"vbiofdhz\" } } }"
}
【问题讨论】:
-
我不明白这个问题。
json.dumps()将始终在字符串周围加上引号。 -
为什么
nested_object的值是字符串而不是字典? -
我希望 "another_nested_object" 在输出中像在值对中一样有引号。
-
应该这样做。请发布一些实际代码,很难从您发布的内容中判断出了什么问题。
-
刚刚更新了我的总结
标签: python json string-literals