开发者

NSMutableDictionary sometimes shows value or key with quotes

开发者 https://www.devze.com 2022-12-19 05:40 出处:网络
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:

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".

0

精彩评论

暂无评论...
验证码 换一张
取 消