当前位置 : 主页 > 编程语言 > python >

rest_framework_xml 解析xml成Python 字典格式数据对象

来源:互联网 收集:自由互联 发布时间:2022-07-19
XML UploadResult OriginalInfo Keytest.jpeg/Key Locationqr-code-1305143506.cos.ap-shanghai.myqcloud.com/test.jpeg/Location ETag"930b8ceb82c9e7ed3dc61bdc0f8577065f7484a7"/ETag ImageInfo FormatJPEG/Format Width1664/Width Height2338/Height Qual


XML 

<UploadResult>
<OriginalInfo>
<Key>test.jpeg</Key>
<Location>qr-code-1305143506.cos.ap-shanghai.myqcloud.com/test.jpeg</Location>
<ETag>"930b8ceb82c9e7ed3dc61bdc0f8577065f7484a7"</ETag>
<ImageInfo>
<Format>JPEG</Format>
<Width>1664</Width>
<Height>2338</Height>
<Quality>93</Quality>
<Ave>0xe0e0e0</Ave>
<Orientation>0</Orientation>
</ImageInfo>
</OriginalInfo>
<ProcessResults>
<Object>
<Format>JPEG</Format>
<Width>1664</Width>
<Height>2338</Height>
<Size>234344</Size>
<Quality>93</Quality>
<CodeStatus>1</CodeStatus>
<QRcodeInfo>
<CodeUrl>王懿馨:101005:[object MouseEvent]</CodeUrl>
<CodeLocation>
<Point>1430,396</Point>
<Point>1432,241</Point>
<Point>1586,242</Point>
<Point>1587,397</Point>
</CodeLocation>
</QRcodeInfo>
</Object>
</ProcessResults>
</UploadResult>import io
from rest_framework_xml.parsers import XMLParser

# response.text ==> xml
s = io.StringIO(response.text)
parser_data = XMLParser().parse(s)

解析后数据

{
'OriginalInfo': {
'Key': 'test.jpeg',
'Location': 'qr-code-1305143506.cos.ap-shanghai.myqcloud.com/test.jpeg',
'ETag': '"930b8ceb82c9e7ed3dc61bdc0f8577065f7484a7"',
'ImageInfo': {
'Format': 'JPEG',
'Width': 1664,
'Height': 2338,
'Quality': 93,
'Ave': '0xe0e0e0',
'Orientation': 0
}
},
'ProcessResults': {
'Object': {
'Format': 'JPEG',
'Width': 1664,
'Height': 2338,
'Size': 234344,
'Quality': 93,
'CodeStatus': 1,
'QRcodeInfo': {
'CodeUrl': '王懿馨:101005:[object MouseEvent]',
'CodeLocation': {
'Point': '1587,397'
}
}
}
}
}

 

上一篇:python中for循环的底层实现
下一篇:没有了
网友评论