I'm relatively new to iOS programming. However, I would have assumed that Swift would have an automated way of converting objects to JSON and vice versa. That being said, I have found several libraries that can do this.
然而
看起来,无论您如何将数据发布到web服务(甚至使用AlamoFire之类的工具),请求都必须是字典.所有这些论坛都展示了如何轻松地将返回的JSON字符串转换为对象.符合事实的但请求需要手动编码.也就是说,遍历所有对象属性并将它们映射为字典.
所以我的问题是:我错过了什么吗?我是否完全弄错了,有一种超级简单的方法可以(a)在请求中发送JSON(而不是字典),或者(b)自动将对象转换为字典?
Again, I see how easy it is to deal with a JSON response. I'm just looking for an automatic way to convert the request object I want to post to a web service into a format that a library like AlamoFire (or whatever) requires. With other languages this is fairly trivial, so I'm hoping there's an equally easy and automated way with Swift.