0

I am working with iCloud first time. I uploaded the data to iCloud database successfully.

I wrote the following code to retrieve the data:

[[iCloud sharedCloud] retrieveCloudDocumentWithName:
          @"SessionInfo.plist" completion:
          ^(UIDocument *cloudDocument, NSData *documentData, NSError *error) {

  NSError *error;
  id dict = [NSJSONSerialization
  JSONObjectWithData:documentData options:NSJSONReadingMutableLeaves error:&error];

Here dict is nil. Error message is 'json string did not start with array or object for iCloud'.

Sujit
  • 21
  • 2
  • [This question](http://stackoverflow.com/questions/21749751/download-and-save-icloud-data-in-plist-format-in-document-folder) is very similar -- are you posting from both your and user3305252's account? If this is the case, please merge your question to one and delete the other. – phi Feb 13 '14 at 09:25

1 Answers1

0

That's not the error message, because that's not an error that NSJSONSerialization can return. Most likely the error message was something like The data couldn’t be read because it isn’t in the correct format or JSON text did not start with array or object and option to allow fragments not set. It's important to include the exact error message when asking a question if you want people to know what you're talking about.

Assuming that the error matches what I think it matches, the answer is simple: Your documentData object does not contain valid JSON. As a result NSJSONSerialization can't convert it to a dictionary. The first argument to that method must contain valid JSON data encoded into an NSData object.

It's impossible to be certain why this is, since you didn't describe the data you're working with. However since you're using a file name of SessionInfo.plist, you're probably working with a property list. Property lists are not JSON. Valid property list file formats include XML, binary (undocumented format), and ASCII (obsolete but still readable). None of those are JSON, and none will work with NSJSONSerialization.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170