【发布时间】:2011-11-20 07:50:32
【问题描述】:
以下是来自 PHP 网页的编码 JSON 数据。
{
{
"news_date" = "2011-11-09";
"news_id" = 5;
"news_imageName" = "newsImage_111110_7633.jpg";
"news_thread" = "test1";
"news_title" = "test1 Title";
},
{
"news_date" = "2011-11-10";
"news_id" = 12;
"news_imageName" = "newsImage_111110_2060.jpg";
"news_thread" = "thread2";
"news_title" = "title2";
},
// and so on...
}
我想获取一组信息(日期/id/图像/线程/标题),并将其存储为类的实例。但是,我不知道如何访问二维数组中的每个对象。 以下是我编写的代码,用于测试我是否可以访问它们,但它不起作用。
会有什么问题?
NSURL *jsonURL = [NSURL URLWithString:@"http://www.sangminkim.com/UBCKISS/category/news/jsonNews.php"];
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL];
SBJsonParser *parser = [[SBJsonParser alloc] init];
contentArray = [parser objectWithString:jsonData];
NSLog(@"array: %@", [[contentArray objectAtIndex:0] objectAtIndex:0]); // CRASH!!
【问题讨论】:
标签: objective-c json multidimensional-array