Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:47:50+00:00 2026-05-31T15:47:50+00:00

I am converting a JSON file to a plist using the new NSJSONSerialization class

  • 0

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!

NSData *data = [[NSData alloc] initWithContentsOfURL:path]; \\(NSURL *)path -->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:&writeToFileError];

Then, at this last line, an NSInvalidArgumentException is thrown, and crashes my program. However, the plist was successfully generated! I can read it, and all is well, except my program crashes.

Could someone please explain why this crashes, and how I could avoid crashing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:47:51+00:00Added an answer on May 31, 2026 at 3:47 pm

    The problem seems to be that the variable plist is type id. Cast it to NSData and you should be fine.

    NSData *plist = (NSData *) [NSPropertyListSerialization ...];
    

    As you correctly point out in the comment, NSData should use the writeToFile:atomically: method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Converting XML to JSON using Python? I am importing an XML feed
Possible Duplicate: Converting XML to JSON using Python? I'm doing some work on App
What's wrong here? res.render('/somepage', {user:req.session.user}) It leads to Converting circular structure to JSON errors,
I am parsing data from a json file and converting to a HTML table,
I am converting image to NSdata using UIImageJPEGRepresentation(image, 1.0) and then encoding it to
I use jackson for converting JSON to Object class. JSON: { aaa:111, bbb:222, ccc:333
I'm currently puling data from an external XML file and converting it to JSON
For converting a integer into an enum (out of a json file), I declared
What is the best way of converting a multi-dimensional javascript array to JSON?
Converting my current code project to TDD, I've noticed something. class Foo { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.