如何使用“SwiftyJSON”将`JSON.Element`转换为`JSON`?

时间:2018-02-05 04:16:19

标签: swift swift4 swifty-json

我想在下面这样做。如何使用“SwiftyJSON”将JSON.Element转换为JSON

public func convert() -> String? {
    let json :JSON = ["Animals" : ["dog","cat"], "Shop":"Tokyo"]
    let animals = json["Animals"]
    let repezentativeAnimal = animals.first
    repezentativeAnimal!["Shop"] = json["Shop"] // Value of tuple type 'JSON.Element' (aka '(String, JSON)') has no member 'subscript'

    // I want to return String below
    //  ["dog":"---", "Shop":"Tokyo"]
    return repezentativeAnimal.rawString() // error : Value of type 'JSON.Element?' (aka 'Optional<(String, JSON)>') has no member 'rawString'
}

1 个答案:

答案 0 :(得分:-1)

pod安装

  

pod'Alamofire-SwiftyJSON'

并导入您的VC

  

导入SwiftyJSON

     

导入Alamofire_SwiftyJSON