例如,我有一个json
var json = JSON(data: data!)
在里面我引用了对象
var list = json["OBJECT"]
有没有办法,我可以检查它是一个对象,数组,或字符串并返回bool?
这没有帮助.var list将永远是类型JSON.我想找到一种方法来检查里面是什么.
vad*_*ian 13
SwiftyJSON中的JSON对象具有type类型为的属性enum
public enum Type: Int {
case number
case string
case bool
case array
case dictionary
case null
case unknown
}
Run Code Online (Sandbox Code Playgroud)
例如
var list = json["OBJECT"]
switch list.type {
case .array: print("list is Array")
case .dictionary: print("list is Dictionary")
default: break
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2225 次 |
| 最近记录: |