I am using JSON-RPC to communicate between iOS application and the server. Some return values of the server are optional.
Considering the combination of technologies I am using, is it better to return these null values like {“telephone”: null} or by completely omitting the “telephone” element in the response?
Futher explanation of what I am asking:
It doesn’t look like the JSON-RPC spec specifies much to do with the method result (please correct me if I’m wrong) and clearly not sending loads null elements would improve performance and reduce bandwidth somewhat. What I’m most interested in though is the best approach from an iOS NSJSONSerialization perspective. Is it easier/better to check for whether a key exists in an NSDictionary or whether an existing key has a null value?
First of all {“telephone”: “null”} is not a null value. There are quotes so actually telephone property has string value with text “null”. Server needs to send {“telephone”: null} – without quotes.
I’d go with listing all relevant properties that your app needs in response and put null as a value if there is not value. Then you can easily check in NSDictionary you get from NSJSONSerialization if value for key is NSNull.