我在这里有这个 PHP 脚本,可以将数组转换为 json:
while($row = $result->fetch_row()){
$array[] = $row;
}
echo json_encode($array);
返回这个
[["No","2013-06-08","13:07:00","Toronto","Boston","2013-07-07 17:57:44"]]
现在我尝试将此 json 代码中的值显示到我的应用程序标签中。这是我的 ViewController.m 文件中的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *strURL = [NSString stringWithFormat:@"http://jamessuske.com/isthedomeopen/isthedomeopenGetData.php"];
// to execute php code
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
// to receive the returend value
/*NSString *strResult = [[[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding]autorelease];*/
self.YesOrNow.text = [NSJSONSerialization JSONObjectWithData:dataURL options:0 error:nil];
}
但是我的标签 YesOrNow 没有显示任何内容:(我做错了什么?
我需要安装 JSON 库吗?