我该如何解析json的post方法? [英] How can I parse post method of json ?
本文介绍了我该如何解析json的post方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我的朋友。
i下载数据的代码如下:
让参数= [
NationalCode:06097732 ,
密码:0012
]
let url =http:// android / home / login
Alamofire.request(url,method:.post ,参数:参数,编码:URLEncoding.httpBody).responseJSON {响应在
如果让data = response.data {
let json = String(data:data,encoding:String.Encoding .nonLossyASCII)
print(json)
self.lbl1.text = json
}
}
我的确有以下结果:
{\id \:\3 \ ,\name \:\jac \}
naw我想要分开每一项结果。这意味着我在一个标签上打印id,在另一个标签上打印name。
我怎么能这样做?
(我是swift的新手)< br $> b $ b
我尝试了什么:
i将此代码打印出来之前(json) ):
如果让q = json为?字典< String,AnyObject> {
如果让PName = q [name]为?字符串{
self.lbl1.text = PName
}
}
解决方案
我不是Swift开发人员,所以我无法为您调试代码。我能做的就是为你提供方向,找到有助于你编程的有用信息(又名:解决问题)。
这是一个快速的Google搜索:在swift中解析json - Google搜索 [ ^ ] br />
它找到了许多编码示例,例如:
* 在Swift中使用JSON -
Apple文档 [ ^ ]
* Swift JSON教程:使用JSON [ ^ ]
* 在Swift 4中解析JSON - Grok Swift [ ^ ]
* GitHub - SwiftyJSON / SwiftyJSON:在Swift中处理JSON数据的更好方法 [< a href =https://github.com/SwiftyJSON/SwiftyJSONtarget =_ blanktitle =New Window> ^ ]
* 在Swift中使用JSON [ ^ ]
* 以及更多! [ ^ 一>
hi my friends.
i have below code for download data :
let parameters = [ "NationalCode": "06097732", "password": "0012" ] let url = "http://android/home/login" Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding.httpBody).responseJSON { response in if let data = response.data { let json = String(data: data, encoding: String.Encoding.nonLossyASCII) print(json) self.lbl1.text=json } }
and i have true result that is:
"{\"id\":\"3\",\"name\":\"jac\"}"
naw i want separe each item of result. it mean i print "id" in one label and "name" in another label.
how can i do this???
(i am new in swift)
What I have tried:
i put this code before print(json):
if let q=json as? Dictionary<String,AnyObject>{ if let PName=q["name"] as? String{ self.lbl1.text=PName } }
解决方案
I am not a Swift developer so I can't debug your code for you. What I can do is offer you direction on where to find useful information that should help you with your programming (aka: problem solving).
Here is a quick Google Search: parse json in swift - Google Search[^]
Which finds a number of coding examples like:
* Working with JSON in Swift -
Apple Documentation[^]
* Swift JSON Tutorial: Working with JSON[^]
* Parsing JSON in Swift 4 - Grok Swift[^]
* GitHub - SwiftyJSON/SwiftyJSON: The better way to deal with JSON data in Swift[^]
* Working With JSON in Swift[^]
* and much more![^]
这篇关于我该如何解析json的post方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文