SwiftyJSON - 'inout JSON'无法转换为'JSON' [英] SwiftyJSON - 'inout JSON' is not convertible to 'JSON'
问题描述
我正面临一个JSON解析问题我不知道如何修复。
I'm facing a JSON parsing issue I've no idea how to fix.
我需要这部分JSON数据
I need this part of the JSON data
columns:{
created_at:DESC,
id:DESC
}
存储在 [String:String]?
可选字典中。所以,这是我正在使用的代码:
to be stored in a [String: String]?
optional dictionary. So, this is the code I'm using:
self.columns = json["columns"].dictionary?.map {
(key, value) -> (String, String) in
return (key, value.stringValue)
}
<然而,这会产生编译错误:
This however produces a compiler error:
'inout JSON'不能转换为'JSON'
'inout JSON' is not convertible to 'JSON'
我应该补充一点,这是一个非常大的JSON数据的一部分,这是导致问题的唯一一个。
I should probably add that this is part of a pretty large piece of JSON data, and this is the only one causing issues.
任何线索都会受到最高的评价,我有点困惑于此。
Any clues would be most appreciated, I'm kind of stuck on this one.
推荐答案
Michael,我解析JSON与例程,不禁认为它比你的更简单,但它的工作原理:) filesQ.enqueue本质上是一个数组,它添加了我想要的字段。
Michael, I parse JSON with routine, cannot help but think it is a little more simplistic than yours, but it works :) filesQ.enqueue is an array in essence it adds the fields I want to.
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)
}
}
如果你设法改进它,请寄回给我一份!
Please send me back a copy if you managed to improve it!
这篇关于SwiftyJSON - 'inout JSON'无法转换为'JSON'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!