arrayWithContentsOfURL的正确用法是什么?

Mik*_*e A 4 iphone objective-c

这有点基本; 我正在尝试检索iPhone应用程序的http数据.

我有www.myhost.com/test.html

<array><string>test</string><string>test2</string></array>
Run Code Online (Sandbox Code Playgroud)

然后我有

NSURL *baseURL = [NSURLRLWithString:@"http://www.myhost.com/test.html"];
NSArray *array = [NSArray arrayWithContentsOfURL:baseURL];
NSLog(@"%@", [array description]);
Run Code Online (Sandbox Code Playgroud)

哪个继续返回(null).我错过了什么?谢谢!

cob*_*bal 5

它应该是一个完整的plist格式(使用doctype和所有)

手册页

创建合适的plist的最简单方法是使用"Property List Editor.app"

旁注:NSLog(@"%@", [array description]);与...相同NSLog(@"%@", array);


luv*_*ere 5

arrayWithContentsOfURL文件明确指出,

由aURL标识的位置处的数组表示必须仅包含属性列表对象(NSString,NSData,NSArray或NSDictionary对象).

也就是说,通过调用writeToURL:atomically方法获得的对象类型.此方法写入的位置可用于使用类方法arrayWithContentsOfURL:或实例方法初始化新数组initWithContentsOfURL:.因此,我建议使用这些标准方法从URL编写和读取数组,而不是编写自己的文件并尝试通过它来读取arrayWithContentsOfURL:.