我遇到了 JSON 解析问题,我不知道如何解决。
我需要这部分JSON数据
“列”:{
"created_at": "DESC",
“id”:“DESC”
}
要存储在 [String: String]?
可选字典中。所以,这是我正在使用的代码:
self.columns = json["columns"].dictionary?.map {
(key, value) -> (String, String) in
return (key, value.stringValue)
}
然而,这会产生编译器错误:
'inout JSON' is not convertible to 'JSON'
我应该补充一点,这是相当大的 JSON 数据的一部分,而且这是唯一导致问题的数据。
任何线索将不胜感激,我有点被困在这个问题上。
最佳答案
Michael,我用例程解析 JSON,忍不住认为它比你的简单一点,但它有效:) filesQ.enqueue 本质上是一个数组,它添加了我想要的字段。
func jsonParser(json2parse: AnyObject, field2file: String) -> Int {
if (json2parse is NSDictionary) {
for (key,value) in json2parse as! NSDictionary {
switch (value) {
case is NSDictionary:
self.jsonParser(value as! NSDictionary, field2file: field2file)
break
case is NSArray:
self.jsonParseArray(value as! NSArray, field2file: field2file)
break
case is NSString:
parsedJson[key as! String] = value
if (key as! String == field2file) {
let file2file = self.parsedJson[field2file] as? String
filesQ.enqueue("ignore", theFile: file2file!)
}
break
default:
break
}
}
}
return(filesQ.qcount())
}
func jsonParseArray(json2parse: AnyObject, field2file: String) {
for (item) in json2parse as! NSArray {
self.jsonParser(item, field2file: field2file)
}
}
如果您改进了它,请发回给我一份副本!
关于ios - SwiftyJSON - 'inout JSON' 不可转换为 'JSON',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35598834/