NSMutableDictionary sometimes shows value or key with quotes
I am parsing a data file and adding the key-value read from the file into an NSMutableDictionary.
I have noticed that when I print out the content of the dictionary in the debugger, i.e: po myDictionary
some entries have quotes around them and some don't. Why is this?
For instance I see:
{
"file_path" = "../dat.txt"
another_path = "aa.dat"
yet_another_path = bb.txt
}
I am using the following line to extract the key and value from the file, after parsing the data down to only the essential bytes
key_str = [[NSString alloc] initWithBytes:[data bytes]
l开发者_Go百科ength:total_bytes
encoding:NSUTF8StringEncoding];
val_str is parsed the same way.
Thank you
You should not use the output of the -debugDescription
or -description
methods for the purposes of data archival. The format is an implementation detail and subject to change.
I would suggest that you look to NSPropertyListSerialization (and related) to solve your archival needs. It offers an XML format, if you need something akin to human readability.
I am experiencing the same issue. It appears to be a problem with the JSON parser putting quotes around Keys that contain the underscore character. So a key of filename is ok but a key with file_name is returned as "file_name".
精彩评论