1

我想用 URL 文件中的内容填充 NSMutableDictionary。它必须是什么类型的文件以及它必须如何构建?

NSMutableDictionary *myMutableDictionary = [[NSMutableDictionary alloc] 
    initWithContentsOfURL:[NSURL URLWithString:@"http://example.com/list.txt"]]; 
4

1 回答 1

1

It has to be in the XML property list format 1:

An URL that identifies a resource containing a string representation of a property list whose root object is a dictionary. The dictionary must contain only property list objects (instances of NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary).

See here for an overview of the property list types.

E.g. the following file:

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

... becomes a dictionary containing:

{
  A = something;
  B = 42;
}
于 2010-05-23T00:36:11.763 回答