What is the best way to get data from the internet, compressed and composed by PHP, to an iOS app?
Currently, the app reads a string formatted like this:
category1#object2#object3#object4~category2#object2#object3[…]
And that is split up by the #‘s and ~‘s.
Is there a better way to do this, both in the way the data is retrieved (the site it gets it from is open for everyone), and the way the data is formatted?
Use JSON:
So say you had a PHP object or associative array, you’d be able to simply invoke
json_encodeon it and be done with it.On the iOS end, you’d want to use JSONKit to parse it.
The best thing about these two ends of the pipeline is that there is native support for them. For example,
json_encodecan encode any PHP object to a readable JSON string, while JSONKit can parse a JSON object and store it in anNSDictionaryorNSArray.Heck, with JSONKit, it augments the capability (using categories on
NSDictionaryandNSArray) to convertNSDictionaryandNSArrayobjects into JSON, so you can even have a two-way JSON communication pipeline.(We do this with our games at Freeverse, the methodology is tried and tested.)