Serving a json file for IPHONE app
I am trying to get an introduction to serving files to the iphone. I have watched tutorials on getting files from sites like Flickr and twitter. I need a tutorial to show me how to set up the site that is feeding that information. Most of those sites send you a json fil开发者_如何学Pythone. Can I just keep a dynamic file on a server using php?
PHP has some great json functions. See json_encode, which takes a PHP structure and converts it to a json string, and json_decode, which does the opposite. Make sure you set a Content-type: application/json
header, echo the result of json_encode, and your iPhone app should be able to read it. Similarly, you can use json_decode to read JSON data that has been sent to your PHP script using GET or POST (preferably the latter).
All those sites use a web service to achieve the json response, depending on what you are using the ability to send back json responses might be built in to the services framework etc (.net for example), here is a question that talks about using .net to make a webservice iPhone interaction with ASP.NET WebService, im sure you can find many more out there
Found this tutorial once i got a better understanding of what i needed to do. http://davidwalsh.name/web-service-php-mysql-xml-json
精彩评论