从iPhone上的字符串加载数组


Load array from string on iPhone

我有一个PHP文件在我的网站上输出的名称列表,每行一个。我想把这些项目加载到tableview中,但是不能让它工作。

I have try:

NSURL *urlVersion = [NSURL URLWithString: @"http://mywebsite.com/users.php"];
NSString *webVersion = [NSString stringWithContentsOfURL:urlVersion encoding:1 error:NULL];
NSString *contents = [NSString stringWithContentsOfFile:webVersion encoding:NSUTF8StringEncoding error:nil];
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:[contents componentsSeparatedByString:@"'n"]];

服务器上的文件是users.php

谢谢!

编辑:通过将整个网站作为字符串,然后解析它以每行分隔来获得它。

您必须向该脚本发出请求:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://mywebsite.com/users.php"]];
NSURLResponse *response = nil;
NSError *resultError = nil;
NSData *resultsData = [NSURLConnection sendSynchronousRequest: request returningResponse: &response error: &resultError];
NSString *resultString = [[NSString alloc] initWithData:resultsData encoding:NSUTF8StringEncoding];

你必须解析这个字符串