IOS开发,已经解析出JSON,如何获取里面的内容
如题,我用AFnetworking解析出json,结果如下:{"viewlist":[{"url1":"/main_System/Status/tatustype_aja...
如题,我用AFnetworking解析出json,结果如下:
{
"viewlist": [
{
"url1": "/main_System/Status/tatustype_ajax.php"
},
{
"url2": "/main_System/Status/Summary_originalevent_ajax.php"
},
{
"url3": "/main_System/Status/Summary_ha_statue_ajax.php"
}
]
}
我想得到,其中,每一个网址,我应该怎么做? 展开
{
"viewlist": [
{
"url1": "/main_System/Status/tatustype_ajax.php"
},
{
"url2": "/main_System/Status/Summary_originalevent_ajax.php"
},
{
"url3": "/main_System/Status/Summary_ha_statue_ajax.php"
}
]
}
我想得到,其中,每一个网址,我应该怎么做? 展开
2个回答
展开全部
1,首先获取文件目录
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
chatFile = [[NSString alloc] initWithString:[documentsDirectory stringByAppendingPathComponent:CHATSFILE_NAME]];
2,加载文件
- (void) loadThread:(NSString *)xmlFile {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSXMLParser *chatLogParser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURLfileURLWithPath:xmlFile]];
[chatLogParser setDelegate:self];
[currentString setString:@""];//记录当前节点的值
[currentChatInfo removeAllObjects];//节点对象
[chatLogParser parse];//开始XML解析
chatLogParser release];
[self performSelectorOnMainThread:@selector(finshLoadFile) withObject:nil waitUntilDone:YES];//创建线程
[pool release];
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
chatFile = [[NSString alloc] initWithString:[documentsDirectory stringByAppendingPathComponent:CHATSFILE_NAME]];
2,加载文件
- (void) loadThread:(NSString *)xmlFile {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSXMLParser *chatLogParser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURLfileURLWithPath:xmlFile]];
[chatLogParser setDelegate:self];
[currentString setString:@""];//记录当前节点的值
[currentChatInfo removeAllObjects];//节点对象
[chatLogParser parse];//开始XML解析
chatLogParser release];
[self performSelectorOnMainThread:@selector(finshLoadFile) withObject:nil waitUntilDone:YES];//创建线程
[pool release];
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询