The gist of my question is: how can I convince PHP to encode/decode json without converting [NS]arrays or [NS]dictionaries to the other one?
I've got an app (iOS, though it shouldn't matter) that keeps a bunch of app data in an NSDictionary. Some of the data is nested a few levels, and some of the objects stored in my top-level dictionary are NSArray-s, or other NSDictionary-s, some of which contain additional NSArray-s or NSDictionary-s.
It's not really all that complicated, and the code traverses it all just fine, so that's all well & good.
I save this top-level dict to a server and, to do so, I use NSJSONSerialization, zip the resulting string and upload it. Later, the server sends back the zip file, I use NSJSONSerialization to decode, and we're all back in business -- again, all well & good.
The problem arrises in that, under certain circumstances, I want the server to unzip the file, json-decode the contents, alter the contents, json-encode the result, and re-zip before sending the data back to the app.
"So what's the problem?", I hear you ask. Aha!
The problem is: the server is PHP and uses json_encode() and json_decode() and, if my data contains empty dictionaries, they are converted to arrays, which makes my data-parsing code unhappy.
Further, if I use json_encode($foo, JSON_FORCE_OBJECT), that turns all arrays into dictionaries (keyed by index, if they didn't used to be dictionaries), which is every bit as bad.
So my question is:
Is there any way in PHP to encode/decode json such that what began life as an array remains an array (in the NSArray sense) and what began life as a dictionary (NSDictionary) remains a dictionary (PHP: "object"), regardless of whether the source data has contents or is empty?
Thanks!
(Yes, I googled around. That's how I learned about JSON_FORCE_OBJECT, but I was unable to find anything to help with this specific problem.)