如何向服务器发出Json请求?
我正在做一个应该与服务器一起工作的应用程序。
需要通过程序使用用户名和密码在服务器上进行授权。 我需要使用以下行向服务器发出请求:
{"login": "mad_fashist", "password": "eqeeuq313371", "method": "authentificator"}
该字符串必须位于杰森。
作为响应,如果身份验证失败,我应该得到一行:
{"validated": "false", "kuid": "", "sid": "", "uid": ""}
并且如果认证通过:
{"validated":"true","kuid":"6","sid":"834fe9b4626502bf9ff23485a408ac40","uid":"69"}
问题是如何发送和接收所有以上?
I'm doing an application that should work with the server.
Need to be authorized on the server through the program using the username and password.
I need to make a request to the server with the line:
{"login": "mad_fashist", "password": "eqeeuq313371", "method": "authentificator"}
The string must be in Json.
In response, I should get a line if authentication fails:
{"validated": "false", "kuid": "", "sid": "", "uid": ""}
And if authentication is passed:
{"validated":"true","kuid":"6","sid":"834fe9b4626502bf9ff23485a408ac40","uid":"69"}
The question is how to send and receive all of the above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用SBJson框架。并执行以下操作:
您的后端应该定义 Json 中的响应的样子
Use SBJson framework. and do smth like:
It's your back end who should define how the response in Json will look like
请参阅 NSJsonSerialization 类。这是ios5.0中新包含的。这是满足您需求的最灵活的一种。您可以在苹果开发者网站中访问它。
链接到 NSJSONSerialization
Refer NSJsonSerialization class. Which is newly included in ios5.0. which is the most flexible one for your need. you can access it in apple developer site.
link to NSJSONSerialization