【问题标题】:map top level JSON String array Object Mapper映射顶级 JSON 字符串数组对象映射器
【发布时间】:2016-04-16 06:38:54
【问题描述】:

如何 mpa 顶级 JSON 字符串数组

来自服务器的 JSON 响应

[
        "tag1",
        "tag2",
        "tag3",
        "tag4",
        "tag5",
        "tag6"
]

我正在使用ObjectMapper Swift

【问题讨论】:

  • 你需要提供一些你迄今为止尝试过的例子。

标签: ios swift objectmapper


【解决方案1】:

在没有 ObjectMapper 的情况下解决它:

根据服务器的响应,将原始 JSON 转换为 String 数组

...
..
    case .Success(let request, _, _):
                self.request = request.responseJSON{ json in
                    if json.result.isSuccess {
                        if let tags =  json.result.value as? [String]{ // Cast it as String Array
                            self.remoteTags.removeAll()
                            tags.forEach{self.remoteTags.append($0)}

                        }
                        self.reloadData()
                    }
                }
...
..

[注意:使用 Alamofire 进行网络操作]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-29
    • 1970-01-01
    • 2019-09-18
    • 2012-01-23
    • 2013-06-15
    • 1970-01-01
    • 1970-01-01
    • 2014-10-31
    相关资源
    最近更新 更多