Karuppu MGR Karuppu MGR - 1 year ago 95
iOS Question

Creating a json object from nsmutable array

I have got three nsmutablearray imageNameArray,imageSizeArray,baseArray.

I have to create a json of following type.

"documents": [
"file_size": 48597,
"file_name": "pisa-en.pdf",
"file_content": "base64String"

since the number of elements within document array might vary, Im trying to create nsdictionary from arrays as follows,

for (int i = 0; i< [_imageNameArray count]; i++){
[dictionary setValue:self.imageNameArray[i] forKey:@"file_name"];
[dictionary setValue:self.imageSizeArray[i] forKey:@"file_size"];
[dictionary setValue:self.baseArray[i] forKey:@"file_content"];


but it is not creating the json of required type. When Im trying to print it, there exists an equals to symbol between key and value.

Answer Source

No need to check in console that it is equal symbol or colon. If you want to send data to server then first convert it in data like,

NSDictionary *dict ; // your dict or array

NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:0 error:nil];

It will convert it in colon (:) instead of =.

And if you are using AFNetworking then you not need to do this jsonserialization, you can directly pass dictionary or array as parameter in method and afnetworking manage all things.

Hope this will help :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download