【发布时间】:2017-02-25 17:14:01
【问题描述】:
这听起来像是一个普通的问题,但我还没有找到一个很好的答案来解决我想要做的事情。
取d.json:
{"SDA":{"Info":{"Description":"Anti Advertisment Bot, Blocks invites extensively.","Download Link":"http://sda.khionu.net/docs/, http://sda.khionu.net/docs/"}}, "Unit 02":{"Info":{"Description":"Server logging bot, c!serverlogs 'server name here if spaces' <# 1-9999>","Download Link":"https://discordapp.com/oauth2/authorize?client_id=222881716606468096&scope=bot&permissions=32768"}}}
我正在尝试添加它,用逗号分隔:
{'Ctest': {'Info': {'Description': 'Hi', 'Download Link': 'Sure'}}}
我尝试了多种方法来做到这一点,但都没有奏效。这是我当前的代码
a = d[toolname] = {str(toolname):{"Info":{"Description": tooldesc, "Download Link": toollink}}}
f.write(str(a))
f.close()
return jsonify(a), 201
我的全部目标是写作
{'Ctest': {'Info': {'Description': 'Hi', 'Download Link': 'Sure'}}}
到 d.json 像这样
{"SDA":{"Info":{"Description":"Anti Advertisment Bot, Blocks invites extensively.","Download Link":"http://sda.khionu.net/docs/, http://sda.khionu.net/docs/"}}, "Unit 02":{"Info":{"Description":"Server logging bot, c!serverlogs 'server name here if spaces' <# 1-9999>","Download Link":"https://discordapp.com/oauth2/authorize?client_id=222881716606468096&scope=bot&permissions=32768"}}, {'Ctest': {'Info': {'Description': 'Hi', 'Download Link': 'Sure'}}}
【问题讨论】:
-
你还没有找到关于解析 JSON 和制作 Python 字典的好参考吗?
-
您需要在 JSON 中使用方括号
[来表示值数组 - 花括号{用于对象(命名属性)