我正在尝试创建一个嵌套的 Json 结构,如下所示:
示例 Json:
{
"id" : "de",
"Key" : "1234567",
"from" : "test@test.com",
"expires" : "2018-04-25 18:45:48.3166159",
"command" : "method.exec",
"params" : {
"method" : "cmd",
"Key" : "default",
"params" : {
"command" : "testing 23"
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试从 OrderedDict 中执行此操作。我不确定构造 OrderedDict 以便生成正确的 Json 的正确方法。
Python代码:
json_payload = OrderedDict(
[('id', id),
('Key', keystore),
('from', 'test@test.com'),
('expires', expires),
('command', 'method.exec')]
# What goes here for the params section??
)
print json.dumps(json_payload, indent=4, default=str)
Run Code Online (Sandbox Code Playgroud)