swift - 如何使用 `JSON.Element` 将 `JSON` 转换为 "SwiftyJSON"?

标签 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'
}

最佳答案

pods 安装

pod 'Alamofire-SwiftyJSON'

并导入你的VC

import SwiftyJSON

import Alamofire_SwiftyJSON

关于swift - 如何使用 `JSON.Element` 将 `JSON` 转换为 "SwiftyJSON"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48615806/

相关文章:

macos - 沙盒应用程序自动启动,无需 ServiceManagement

swift - fatal error : Array index out of range in uitableview on back to previous controller swift

ios - Swift URL appendingPathComponent 将 `?` 转换为 `%3F`

ios - 删除事件后 TableView 中的奇怪行为

json - Alamofire 和 SwiftyJSON

json - 如何将 DispatchSemaphore 与 Alamofire 和 SwiftyJSON 一起使用?

swift - swift 3 在iPhone 5 屏幕上更新约束后图片不存在

ios - Swift - 将渐变设置为 UITableView 部分背景

ios - 在选项卡式应用程序中保存用户对选项卡的重新排序

SwiftyJSON API 请求返回 Null