dongyi1215 2014-10-09 19:08
浏览 91
已采纳

将php json文件导入swift

I have a website that uses MySQL database. I'm trying to build an iOS app for it, so I wanted to use Swift to import information from the database and insert new information to it. I read that for the reading part I should use a PHP file to create a Json file, read that and extract the data. But I can't find the way to do it with swift.

Is there a way to connect iOS apps (written in Swift) to MySQL?

  • 写回答

1条回答 默认 最新

  • dsbqfrr098575666 2014-10-09 19:17
    关注

    In the client-server architecture, the client is completely separate from the server, and they just exchange data thanks to a common "language" (in your case, certain fields encoded in JSON).

    Your client is your iPhone app, written in Swift (but that's irrelevant).
    You now need to build a server, which is entirely separate from the app. You don't need Swift for that. You will need a server (for example a cheap cloud VPS on Amazon EC2, Rackspace Cloud Servers, Microsoft Azure...) and you will have to create another application that runs on that server.

    If it's just to pull data from a MySQL database, you can easily make that in PHP. Or you could use Node.js (which uses JavaScript: it's among the "trendiest" technologies at the moment), Ruby, Python, etc.
    For an example that uses PHP, you can check: https://stackoverflow.com/a/22367600/192024
    To read the JSON data in your iOS app, then, you can use the builtin libraries: https://developer.apple.com/library/ios/DOCUMENTATION/Foundation/Reference/NSJSONSerialization_Class/index.html (it's available in Swift too)

    I don't know what your app is doing, but if you want to ignore all the things with the backend (the server) you can always consider something like Parse Core and let somebody else take care of the backend.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图