将数据从应用程序存储到服务器上
如何通过 iOS 应用程序将数据存储在服务器上?
如果我创建一个 JSON 对象,如何将其发送到服务器并将其作为某个键的值保存在服务器上?
我目前正在使用 MAMP,并且已经看到了如何在服务器上创建项目并将其发送到手机的示例,我想了解如何在设备上创建对象,并将它们发送到服务器进行存储。例如 JSON 对象,并将其作为具有 ID 的键的值存储在服务器上。
我将非常感谢任何对此的帮助。
How does one store data on a server from an iOS app?
If I create, e.g. a JSON object, how can I send this to the server and save it on the server as the value from some Key?
I am using MAMP at the moment and have seen examples of how to create the item on the server and get it to the phone, I would like to learn how to create objects on the device, send them to the server for storage. such as a JSON object and store it on the server as a value for e.g. a key with an ID.
I would greatly appreciate any help with this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看
NSUrlConnection
。使用它您可以同步和使用 POST 请求异步将数据传输到服务器。Have a look at
NSUrlConnection
. Using it you can synchronously & asynchronously transmit data to your server using a POST request.查看 ASIHTTPRequest。它可以从 URL 异步 GET/POST 并进行存储,如果数据集足够小,请查看 NSUserDefaults。
在服务器端(如果脚本是 PHP),您可以处理 $_POST 和 $_GET 变量中的数据,就像它们是从 Web 填充的一样。
如果您愿意,可以将变量单独发布到它们自己的 $_POST 或 $_GET 变量中,或者作为 1 个 JSON 字符串,您可以 收到后进行解码。
Check out ASIHTTPRequest. It can GET/POST from a URL asynchronously and for storage, if the data set is small enough look at NSUserDefaults.
On the server side (if the scripts are PHP), you can handle the data in the $_POST and $_GET variables just as if they were populated from the web.
If you wanted you could post the variables individually in their own $_POST or $_GET variables, or as 1 JSON string which you could decode when you receive it.
您可能还想查看 RestKit ,它会让下载/上传/处理 JSON 时变得更容易。
You may also want to check out RestKit which will make things easier when dealing with downloading/uploading/processing JSON.