【发布时间】:2019-03-12 15:11:20
【问题描述】:
如何使用 SwiftyJson 在下面的 json 文件中提取所有带有键“text”的值?这是微软认知服务文本识别的回应。
{
"language": "de",
"textAngle": 0,
"orientation": "Up",
"regions": [
{
"boundingBox": "353,597,1926,1277",
"lines": [
{
"boundingBox": "1091,597,410,93",
"words": [
{
"boundingBox": "1091,604,106,84",
"text": "Ka"
},
{
"boundingBox": "1210,597,291,93",
"text": "uflond"
}
]
},
{
"boundingBox": "1122,861,358,89",
"words": [
{
"boundingBox": "1122,866,174,84",
"text": "Kauf"
},
{
"boundingBox": "1314,865,21,85",
"text": "I"
},
{
"boundingBox": "1348,861,132,87",
"text": "and"
}
]
},
{
"boundingBox": "948,982,649,81",
"words": [
{
"boundingBox": "948,986,398,77",
"text": "Schwabenp"
},
{
"boundingBox": "1359,984,19,74",
"text": "I"
},
{
"boundingBox": "1393,986,131,69",
"text": "atz"
},
{
"boundingBox": "1546,982,51,74",
"text": "LI"
}
]
},
{
"boundingBox": "944,1088,665,80",
"words": [
{
"boundingBox": "944,1089,220,79",
"text": "70563"
},
{
"boundingBox": "1210,1088,399,75",
"text": "Stutt
json 文件要大得多,并且有很多不同深度的关键“文本”值,我不知道应该如何遍历整个 Json 主体! 感谢您的帮助
【问题讨论】:
-
如果您使用的是 Swift 4,我们建议您使用 Codable。如果没有,您必须了解 JSON 的结构。这并不复杂,它只是顶层的字典,它有一个关键区域,其值是字典数组等。如有必要,请逐步执行。那么,你有什么尝试吗?
标签: json swift swifty-json