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?

6
  • see this once it helps you stackoverflow.com/questions/35836886/… Commented May 24, 2016 at 11:56
  • if you have a doubt ask me I will added the answer here Commented May 24, 2016 at 11:56
  • I tried but it is not working. thank you Commented May 24, 2016 at 12:14
  • how can I iterate over nsmutablearray of file_size, file_name, file_content and create nsdictionary out of it? Commented May 24, 2016 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 Commented May 24, 2016 at 12:21

1 Answer 1

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];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.