代码之家  ›  专栏  ›  技术社区  ›  Andreas Prang

对于具有contentofurl的nsmutabledictionary,我使用什么类型的文件?

  •  1
  • Andreas Prang  · 技术社区  · 16 年前

    我想用URL文件中的内容填充一个nsmutabledictionary。它必须是什么类型的文件?它必须如何构造?

    NSMutableDictionary *myMutableDictionary = [[NSMutableDictionary alloc] 
        initWithContentsOfURL:[NSURL URLWithString:@"http://example.com/list.txt"]]; 
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   Georg Fritzsche    16 年前

    它必须在 XML property list 格式 1 :

    标识包含属性列表的字符串表示形式的资源的URL,该属性列表的根对象是字典。字典只能包含属性列表对象(nsdata、nsdate、nsnumber、nsstring、nsarray或nsdictionary的实例)。

    见 here 有关属性列表类型的概述。

    例如,以下文件:

    <plist version="1.0">
      <dict>
        <key>A</key><string>something</string>
        <key>B</key><integer>42</integer>
      </dict>
    </plist>
    

    …成为包含以下内容的词典:

    {
      A = something;
      B = 42;
    }