Reputation: 83
is it will be a good practice to call API with json object as input parameter rather than NSDictionary.
Usually we used to send NSDictionary as input parameters. Is there any issue or performance improvement in mobile device or in server side
Upvotes: 0
Views: 86
Reputation: 437622
Yes, it is a fine practice to take your Objective-C NSDictionary
, use NSJSONSerialization
to convert that to JSON (or use a library like AFNetworking that can do that for you) and send the JSON in the network request you send when calling your web service. You would generally not send the NSDictionary
itself (e.g. a plist or keyed archiver). JSON is the lingua franca of web services. (XML is another very common format, though JSON is easier on the iOS side, IMHO.)
If you're building the network request yourself (e.g. building a NSMutableURLRequest
to be sent using NSURLSession
), remember to:
HTTPMethod
to @"POST"
;HTTPBody
to be the JSON;Content-Type
HTTP header to application/json
; andAccept
HHTP header to indicate what format you're expecting the response to be (also likely application/json
). Upvotes: 2