【问题标题】:How to pull country from JSON data如何从 JSON 数据中提取国家/地区
【发布时间】:2018-06-11 04:28:19
【问题描述】:

我正在使用 SwiftyJSON 库进行 JSON 解析。我没有得到这个国家的价值。我想要国家的价值。我想要价值“GB”。

以下是 JSON:

{
    "status": true,
    "message": "Country Details",
    "content": 
    {
        "country": "GB"
    }
}

代码:

let countryJson = response["content"]
let Country = countryJson["country"]

【问题讨论】:

  • 你在这里得到什么结果let countryJson
  • 试试这个let Country = response["content"]["country"].stringValue
  • 你是如何使用 SwiftyJson 的? countryJson 不是 swiftyJson 的 JSON 对象。

标签: json swift swifty-json


【解决方案1】:

试试这个:

let countryJSON = response["content"] as? [String: String]
let country = countryJSON?["country"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-25
    • 2019-10-27
    • 1970-01-01
    相关资源
    最近更新 更多