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 7857549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:04:25+00:00 2026-06-02T21:04:25+00:00

Some jSON comes from a local file that my app decomposes : {1:{name:My List,list:[]}}

  • 0

Some jSON comes from a local file that my app decomposes : {"1":{"name":"My List","list":[]}}.

I use this iOS 5.1 code to convert the entire thing into what I assume to be a deep mutable dictionary, due to the options utilized:

NSData *data = [[NSFileManager defaultManager] contentsAtPath:jSONFile];
NSMutableDictionary *mydict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves error:&error];

Given the option NSJSONReadingMutableContainers I would assume that the child array list would be fall into this category: “NSJSONReadingMutableContainers – Specifies that arrays and dictionaries are created as mutable objects.” from the NSJSONSerialization Class Reference, but when I try to execute the following code:

NSMutableArray *myarray = [mydict objectForKey:@"1"] objectForKey:@"list"];
[myarray addObject:@"test"];

Execution explodes on the second line (addObject) with the following exceptions:

-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x887e840

** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x887e840’

From my SO research (1, 2, 3), it seems that the above error is generally caused when the element (dictionary / array) with which the object is attempting to be added to is not mutable. Furthermore, from my SO research (1, 2), it seems that there is no way to test if an object is indeed mutable in obj-c, and that is by design.

So I guess my question is, how can I ensure that my jSON structure is indeed ‘deep’ mutable upon (or immediately after) serialization? I know I can’t use mutableCopy on mydict because that function is shallow. Any direction / solutions would be greatly appreciated. Thank you.

  • 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-06-02T21:04:28+00:00Added an answer on June 2, 2026 at 9:04 pm

    I have used this implementation which uses a category on nsdictionary to do a mutable deep copy and works great:

    deep mutable copy of a NSMutableDictionary

    So after you deserialize the json, you could just call mutableDeepCopy on it.

    This is what I have:

    @interface NSDictionary(Category)
    - (NSMutableDictionary *)mutableDeepCopy;
    @end
    
    @implementation NSDictionary(Category)
    - (NSMutableDictionary *)mutableDeepCopy{
        NSMutableDictionary * ret = [[NSMutableDictionary alloc]
                                 initWithCapacity:[self count]];
    
       NSMutableArray * array;
    
       for (NSString* key in [self allKeys]){
    
           if([[self objectForKey:key] respondsToSelector:@selector(mutableCopyWithZone:)]){
                array = [(NSArray *)[self objectForKey:key] mutableCopy];
               [ret setValue:array forKey:key];
           }
           else{
                [ret setValue:[self objectForKey:key] forKey:key];
    
           }
        }
    
        return ret;
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you are working with some data, which comes from a JSON file. You
I'm generating an XML from data that comes from database (and some JSON feeds).
I have a JSON string such as below. That comes from a Website (the
I've recently started using GSON library for deserializing JSON that comes from web service
I need to build some JSON out from PHP. The structure of the JSON
I have some json in this structure: {data:{1:file1.gif,2:file2.jpg}} // ... etc I am trying
I have some json files with 500MB. If I use the "trivial" json.load() to
I am consuming some JSON from two different sources, I end up with two
I'm trying to use the PHP json_encode function to encode some JSON to send
I am trying to download some JSON from the google book API. The URL

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.