0

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]
                                   length:total_bytes
                                 encoding:NSUTF8StringEncoding];

val_str is parsed the same way.

Thank you

4

2 回答 2

1

您不应将-debugDescription-description方法的输出用于数据存档。格式是一个实现细节,可能会发生变化。

我建议您使用NSPropertyListSerialization(及相关)来解决您的归档需求。如果您需要类似于人类可读性的东西,它提供了一种 XML 格式。

于 2010-02-08T04:10:21.573 回答
0

我遇到了同样的问题。JSON解析器在包含下划线字符的键周围加上引号似乎是一个问题。所以文件名的键是可以的,但文件名的键返回为“文件名”。

于 2010-12-10T21:27:18.697 回答