ios - objective-c json serialization -
i need create post request , in it's body need put json. template json file follows:
{"key" : [{...}, {...}, {...} ..... ]} what i've tried doing this:
@{@"key" : @[@{...}, @{...} ... ]}; the issue have puts round brackets around nsarray. output:
{key = ({...}, {...}, ..... )} snippet code(after i've created nsdictionary)
nserror *error; nsdata *jsondata = [nsjsonserialization datawithjsonobject:mydictionary options:nsjsonwritingprettyprinted error:&error]; [request sethttpbody:jsondata]; is there way me make nsarray have [ ] instead of ( )?
nslog uses {} printing nsdictionary , () printing nsarray contents. has nothing json. json data structure created , encoded correctly. verify this:
nslog(@"%@", [[nsstring alloc] initwithdata:jsondata encoding:nsutf8stringencoding]); and see actual json printed.
Comments
Post a Comment