从 PHP 或 ASP 中的动态数据库 URL 加载 iPhone 上的 NSArray
我有一个在线数据库,我希望能够将其加载到我的应用程序中的 NSArray 中。我可以将 arrayWithContentsOfURL 与静态文件一起使用,但我确实需要转到从数据库生成 plist 文件并将其加载到数组中的 url。我可以使用 ASP 或 PHP。我尝试将响应类型设置为“text/xml”,但这没有帮助。
有什么想法吗?
I have a database online that I would like to be able to load into an NSArray in my app. I can use arrayWithContentsOfURL with a static file, but I really need to go to a url that generates a plist file from the database and loading it into the array. I can use ASP or PHP. I tried setting the response type to "text/xml", but that doesn't help.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Apple 的 plist 格式不仅仅是任何 xml 模式。您必须在服务器上生成有效的 plist 文件。
例如使用 CFPropertyList。
Apple's plist format is not just any xml schema. You have to generate a valid plist file on your server.
Use for example CFPropertyList.
最好的办法是使用 json。格式良好,代码非常短,轻量级,快速且易于使用。
例如,使用 php 生成数组,即您想要在 obj-c 代码中获得的内容。
然后将您的数组编码为 json 对象,并将
json 框架 复制到您的app 并使用:
现在你的 iphone 代码中得到了与 php 文件中完全相同的数组。
//编辑:
您可以使用
NSURLRequest
获得更好的性能和其他很酷的东西。一探究竟。the best thing is using json. well formatted, very short code, lightweight, fast and easy to use.
for example generate your array with php, what you want to get in your obj-c code.
then encode your array to a json object and echo
copy the json framework to your app and just use:
now you got exactly the same array in your iphone code, as in your php file.
//edit:
you can use
NSURLRequest
for better performance and other cool things. check it out.