字符串转换为Json Array,然后在Swift iOS中解析值? [英] String convert to Json Array and then parse value in swift iOS?

查看:193
本文介绍了字符串转换为Json Array,然后在Swift iOS中解析值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是快速语言的新手.我正在尝试从API调用中获取一些数据,并且对该API的响应是"{状态":1,消息":请输入手机号码"}"

I am new to the swift language. I am trying to fetching some data from an API call and response to that API is "{"status":1,"msg":"Please enter Mobile number"}"

我在字符串中有上述响应,如何将其转换为JSONObject,然后解析并获取状态值?

I have the above response in a string How can I convert this string to JSONObject and then parse it and get status value?

我是一名Android开发人员,我们在调试代码时会对表达式进行评估,而Xcode中也有类似的代码,因此我可以执行一些代码运行时间

I am an android developer we have evaluate expression while debugging code is there some like in Xcode so I can execute some code run time

推荐答案

我建议使用SwiftyJson库. 首先使用http://jsoncafe.com

I suggest use SwiftyJson library . first create a model from your json using http://jsoncafe.com

您可以使用以下代码解析数据并对其建模

you can parse data and model it using the following code

 let json = JSON(response)
 let message = Message(fromJson: json )

然后您可以访问变量=> message.status

then you have access to your variable => message.status

这篇关于字符串转换为Json Array,然后在Swift iOS中解析值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆