我从一个API得到以下响应,我想从Python中的这个对象中提取电话号码。我怎么能做到呢?在
{
"ParsedResults": [
{
"TextOverlay": {
"Lines": [
{
"Words": [
{
"WordText": "+971555389583", //this field
"Left": 0,
"Top": 5,
"Height": 12,
"Width": 129
}
],
"MaxHeight": 12,
"MinTop": 5
}
],
"HasOverlay": true,
"Message": "Total lines: 1"
},
"TextOrientation": "0",
"FileParseExitCode": 1,
"ParsedText": "+971555389583 \r\n",
"ErrorMessage": "",
"ErrorDetails": ""
}
],
"OCRExitCode": 1,
"IsErroredOnProcessing": false,
"ProcessingTimeInMilliseconds": "308",
"SearchablePDFURL": "Searchable PDF not generated as it was not requested."**strong text**}
存储对变量的API响应。我们叫它^{{cd1>}。
现在使用^{cd2>}模块将JSON字符串转换为Python字典。
现在遍历^{cd3>}以获取所需的文本。
^{pr2}$无论字典值是数组,都使用^{{cd4>}访问数组的第一个元素。如果您想访问数组的所有元素,则必须循环遍历数组。
您必须使用库
json
将生成的stirng解析到字典中,然后可以通过在json结构上循环来遍历结果,如下所示:您可能需要检查该进程中是否存在所有键,这取决于您使用的API,比如
^{pr2}$相关问题 更多 >
编程相关推荐