I'm trying to send an archived objective-c object to a php script and then retrieving it from the server and decoding it in the app.
My current workflow:
- Archive object
- Send archive to PHP by posting raw data
- Saving data into mysql blob
- Loading raw data from PHP script
- Decoding object
Only step 1 and 5 is working currently. I can save the data to the blob, but the contents look far from what I actually sent to the php script. I can load the data from the PHP script, but the resulting data doesn't look like what's in the blob when I look at the data in the database.
So my question is开发者_如何学编程: How should I encode the NSData from the archived object for sending to the PHP script? How should I handle the data on the PHP side when inserting it into MySQL? How should PHP send the data back to the app? and... finally... How should the app decode the data from the PHP script so that it becomes readable for the decoder?
Answers and ideas for any of these questions would be a tremendous help :-) thank you.
If the object lends itself, then think about encoding it as a JSON or YAML. Many libraries both in Objective-C and PHP exist for serializing/marshaling those formats and implementing them is pretty straightforward.
If you were doing this in JSON, you might:
1) Encode a JSON string from the Cocoa object 2) POST that to your PHP app 3) Have PHP parse the JSON and write something to MySQL 4) Generate an HTTP response from MySQL's response, encoding it as JSON and sending it back to the client 5) Decode the JSON
And you're done! If that sounds like what you're after, I'd be happy to recommend some good libraries.
精彩评论