使用Alamofire序列化JSON对象

编程入门 行业动态 更新时间:2024-10-22 07:50:25
本文介绍了使用Alamofire序列化JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试序列化JSON响应,但是在 let json = ...行上出现错误。错误是对成员‘jsonObject(with:options :)’的引用不明确。如果有人知道如何解决此问题,我将予以赞赏

Im trying to run to serialize the JSON response, but I am getting an error on the "let json = ..." line. The error is "Ambiguous reference to member 'jsonObject(with:options:)'". If anyone knows how to fix this I will apprechiate it

Alamofire.request("httpbin/get").responseJSON { response in if let JSON = response.result.value { do { let json = try JSONSerialization.jsonObject(with: response.result.value!, options: .allowFragments) } catch { print () } print("JSON: \(JSON)") } }

推荐答案

因为 response.result.value 是字典 __ NSDictionaryI 的类型,而不是 jsonObject 。您可以轻松地从 JSON 检索值,而无需转换为json,例如: JSON [ title]

Because response.result.value is type of a dictionary __NSDictionaryI, not a Data as jsonObject expected. You can retrieve value from JSON with ease, no need to convert to json, for example: JSON["title"]

更多推荐

使用Alamofire序列化JSON对象

本文发布于:2023-11-26 18:03:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   序列化   Alamofire   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!