【发布时间】:2019-03-08 11:15:51
【问题描述】:
我想要 json 对象中的大小值,但问题是我正在获取整个 json 数据,我只想打印大小值
这是我的 json
[{
size = {
height = 20
width = 10
},
number = 100
}]
这是我的代码
do{
let Json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers)
//print(Json as Any)
guard let newValue = Json as? [[String: Any]] else {
print("invalid format")
return
}
print(newValue)
}catch {
print("Response Not Found.")
}
【问题讨论】:
-
您只需要获取尺寸键即可打印尺寸。如需参考,请点击此链接stackoverflow.com/questions/40736924/…
-
你能帮我写个代码吗
-
亲爱的,请先尝试,如果您有任何问题,请告诉我们....我们一定会帮助您....
-
我正在获取整个 json 数据,我只想调整值的大小
-
嘿@username000,你解析后得到的模型是数组。您需要先获取该数组的索引,然后再获取键值对。您的案例将是 newValue[
]["Key"] 或试用,您可以执行 newValue.first["key"]