我有一本字典,如下
{
"a": 2,
"b": 1,
"dd": {
"xx": {
"name": "Xx XxRay",
"guid": "967436db-3f7b-40c3-94cb-45c7ac5a1787"
},
"yy": {
"name": "Yy YyZee",
"guid": "db12b2b3-554d-42a8-b34e-9995c9719999"
}
}
}
我试图在Restx中使用marhsall,但未能成功。
首先,我定义了的内部结构
details_model = api.model('Details', {
"name": fields.String(required=True,
description='Name'),
"guid": fields.String(required=False, description='GUID')
})
其次,我定义我目前没有使用它。
dd_model = api.model('dd', {
'shortname': fields.Nested(details_model)
})
最后,
response_model = api.model('Response', {
'a': fields.Integer(min=0, description='Total Number of Results'),
'b': fields.Integer(min=0, description='Total Number of X'),
'dd': fields.Nested(fields.String, details_model)
})
我该如何构建这个结构??
details_model = api.model('Details', {
"name": fields.String(required=True,description='Name'),
"guid": fields.String(required=False, description='GUID')
})
定义所有子域
dd_model = api.model('dd', {
'xx': fields.Nested(details_model),
'yy': fields.Nested(details_model)
})
最后,
response_model = api.model('Response', {
'a': fields.Integer(min=0, description='Total Number of Results'),
'b': fields.Integer(min=0, description='Total Number of X'),
'dd': fields.Nested(fields.String, details_model)
})