0

I have to make json request of following type.

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

Following is the way how im creating the json.

NSString *json = [NSString stringWithFormat:@"{\"documents\": [ { \"file_size\": %@, \"file_name\": %@\", \"file_content\": \"%@\" } ]}",_imageSizeArray[0],_imageNameArray[0],_baseArray[0]];

but the problem is that, the documents array may even contain more than one json object within it. If thats the case How can i create a jsonobject dynamically and embed it within documents array?

  • see this once it helps you http://stackoverflow.com/questions/35836886/afnetworking-2-0-send-post-request-with-array-of-dictionary-parameters – Anbu.Karthik May 24 '16 at 11:56
  • if you have a doubt ask me I will added the answer here – Anbu.Karthik May 24 '16 at 11:56
  • I tried but it is not working. thank you –  May 24 '16 at 12:14
  • how can I iterate over nsmutablearray of file_size, file_name, file_content and create nsdictionary out of it? –  May 24 '16 at 12:20
  • Also Im facing problem while embedding base64string because it is ignoring the cases that contains "/" and hence json error is being thrown –  May 24 '16 at 12:21
  • Try this it would be helful!! http://stackoverflow.com/questions/16057281/creating-json-format-in-objective-c – Sanjeet Verma May 24 '16 at 13:01

1 Answers1

0

You have to take Array and add document object in that array

than at request time you have to convert your array to json string by following code

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:myArray options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
Shreyank
  • 1,549
  • 13
  • 24