gpt4 book ai didi

ios - 如何使用Alamofire发布SwiftyJSON?

转载 作者:行者123 更新时间:2023-12-01 22:20:26 26 4
gpt4 key购买 nike

我想通过Alamofire发布JSON。

但我不太确定该如何处理。

我的swiftyJSON与我的

如何将JSON数组编码为DictionaryObject?适合

Alamofire's Parameters?

urlRequest = try JSONEncoding.default.encode(urlRequest, with: location)

我的示例JSON如下所示:
"[{\n    acc = accuracy;\n    lat = lat;\n    long = long;\n    type = type;\n}, {\n    acc = accuracy;\n    lat = lat;\n    long = long;\n    type = type;\n}, {\n    acc = accuracy;\n    lat = lat;\n    long = long;\n    type = type;\n}, {\n    acc = accuracy;\n    lat = lat;\n    long = long;\n    type = type;\n}, {\n    acc = accuracy;\n    lat = lat;\n    long = long;\n    type = type;\n}]"

最佳答案

诀窍是您需要将其转换为Dictionary。
示例片段如下:

```

    // let assume swiftyJSON is a SwiftyJSON object (JSON)
if let data = swiftyJSON.rawString()!.data(using: .utf8) {
do {
let json = try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
Alamofire.request(url, method: .post, parameters: json, encoding: JSONEncoding.default, headers: headers).responseJSON { response in
debugPrint(response)
}
} catch {
print("JSONSerialization error")
}
}

```

关于ios - 如何使用Alamofire发布SwiftyJSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45180969/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com