iOS JSON serialization empty array serialized as nil instead of [ ] -


i attempting send json rails backend. when serializing payload (nsdictionary), empty array encoding nil instead of [ ] (empty array).

is json encoding empty nsarray [] not supported on ios?

i have tried changing 'options' within datawithjsonobject: no success. sending along @"[]" regular ol' nsstring not work.

here code:

nsdata* jsondata = [nsjsonserialization datawithjsonobject:payload options:nsjsonreadingmutableleaves error:&error];  [request setvalue:@"application/json" forhttpheaderfield:@"content-type"]; [request sethttpbody:jsondata]; afjsonrequestoperation *authrequest = [afjsonrequestoperation jsonrequestoperationwithrequest:request  success:successblock failure:failblock]; [authrequest start]; 

thanks help!

i suspect problem coming rails , not ios, there issue related security hole in rails since 3.2.11

https://github.com/rails/rails/issues/8832

https://github.com/rails/strong_parameters/issues/82

for example :

sending empty array in body {"bookmarks":[]}

gets serialized in rails : {"bookmarks"=>nil}

to sure problem coming should inspect request using proxy charles.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -