Seeing is not necessarily a real

Source: Internet
Author: User

When parsing json, many people will assign the parsed data to nsdictionary, and fetch the corresponding value by the key value.

Sometimes we make additions or deletions to the data.

In the face of deleting data under a key, the first reaction is to use a mutable dictionary to assign the parsed data to it, but in the process of using it, the program crashes after the Removeobjectforkey method is executed.

But in normal use without any mistakes, can still use other methods to take key or value, this situation is confusing. Please read the error message carefully.

View the crash information under output is

Terminate_handler unexpectedly threw an exception

Using exception capture to see where the problem lies, we put the Removeobjectforkey method in @try

@try {}@catch (nsexception *exception) {     NSLog (@ "%@", exception);} @finally {    NSLog (@ "end");}

The output exception is:

Object

The Removeobjectforkey method cannot be executed on an immutable array.

Originally we used a mutable dictionary to accept the parsed JSON, although it can be used normally, but there are still some problems.

It was found that the mutable dictionary was only seen as mutable on the surface, but in fact it was an immutable dictionary. We have made minor changes to the code, transforming the immutable dictionary into a mutable dictionary for the purpose of deleting the data.

+ (Instancetype) dictionarywithdictionary: (Nsdictionary *) dict;

This allows the Remove method to execute normally.

Seeing is not necessarily a real

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.