如何处理它

2024-09-29 23:17:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个django应用程序,它接受JSON请求,处理请求,将它们作为SOAP转发给API,处理响应,然后将响应作为JSON转发给客户机。在

在响应中没有Iterable的方法运行良好。但对于具有Iterable的方法,它要么返回混乱的响应,要么返回内部错误。在

例如:

class MyCitiesIterable(ComplexModel):
    __namespace__ = MY_NAMESPACE

    ID = Integer
    Description = String


class Other(ComplexModel):
    __namespace__ = MY_NAMESPACE

    Errors = Integer


class MyCitiesResponse(ComplexModel):
    __namespace__ = MY_NAMESPACE

    Cities = Iterable(MyCitiesIterable)
    Other = Other

返回的对象:

^{pr2}$

JSON响应

{ "Cities":
    [
         {
            "Description": "MyCity",
            "ID": [[["Description", "City 1"],
            ["ID", 1]],
            [["Description", "City 2"],
            ["ID", 2]],
            [["Description", "City 3"],
            ["ID", 3]]]}],
            "Other": {"Errors": 0}
        }
    ]
}

Tags: 方法idjsoncitymyintegerdescriptioniterable

热门问题