SwiftyJSON - 'inout JSON' is not convertible to 'JSON'

后端 未结 1 1760
悲哀的现实
悲哀的现实 2021-01-24 10:36

I\'m facing a JSON parsing issue I\'ve no idea how to fix.

I need this part of the JSON data

\"columns\": { \"created_at\": \"DESC\", \"id\": \"DE

1条回答
  •  再見小時候
    2021-01-24 10:57

    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!

    0 讨论(0)
提交回复
热议问题