Note that there are some explanatory texts on larger screens.

plurals
  1. PONSData writeToFile writes Plist successfully, but then crashes, giving NSInvalidArgumentException
    primarykey
    data
    text
    <p>I am converting a JSON file to a plist using the new NSJSONSerialization class and NSPropertyListSerialization class. I manage to convert my JSON to a Plist without errors, but then, at my last step, when I go to write the plist to my desktop, the program crashes, but AFTER the Plist has been generated!</p> <pre><code>NSData *data = [[NSData alloc] initWithContentsOfURL:path]; \\(NSURL *)path --&gt;goes to my JSON file NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; //the following removes all key/object pairs where the object is null, because NSPropertyListSerialization with throw an error if there are null values for (id __strong object in [json objectForKey:@"terms"]) { if ([object objectForKey:@"image"] == [NSNull null]) { [object removeObjectForKey:@"image"]; } } //the following NSPropertyListSerialization method returns an NSData id plist = [NSPropertyListSerialization dataFromPropertyList:(id)json format:NSPropertyListXMLFormat_v1_0 errorDescription:nil]; NSError *writeToFileError; [plist writeToFile:@"/Users/kalaracey/Desktop/test.plist" atomically:YES encoding:NSUTF8StringEncoding error:&amp;writeToFileError]; </code></pre> <p>Then, at this last line, an <code>NSInvalidArgumentException</code> is thrown, and crashes my program. However, the plist was successfully generated! I can read it, and all is well, except my program crashes. </p> <p>Could someone please explain why this crashes, and how I could avoid crashing?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload