这是我的JSON数据:
{
"SearchList": [
{
"HeadLines NewsIds ": [
"1056305",
"1285209",
"3248204"
],
"NewsText NewsIds ": [
"12328475",
"12328324",
"12328310",
"12325544"
],
"Issuers News Ids": [
"4269",
"21636",
"21828",
"22061"
]
}
]
}
从这个jason formate我需要存储 标题新ids 新闻文字新闻 发行人新闻ids
进入三个不同的阵列.....
答案 0 :(得分:1)
安装JSONKit并使用以下代码:
+(NSDictionary*) parseJson:(NSString*) jsonString {
NSDictionary *rootDict = nil;
NSError *error = nil;
@try {
JKParseOptionFlags options = JKParseOptionComments | JKParseOptionUnicodeNewlines;
rootDict = [jsonString objectFromJSONStringWithParseOptions:options error:&error];
if (!rootDict) {
NSLog(@"%@",[error localizedDescription]);
}
} @catch (NSException * e) {
NSLog(@"%@ %@", [e name], [e reason]);
rootDict = nil;
}
return rootDict;
}
然后像这样迭代生成的NSDictionary
:
NSDictionary *root = [Yourclass parseJson:string];
NSDictionary *elements = [[root objectForKey:@"SearchList"] lastObject];
NSArray *headlines = [elements objectForKey:@"HeadLines NewsIds"];
// ...
答案 1 :(得分:0)
- (void)interceptUrlRequest1:(NSString*)urlString withString:(NSString*)string {
FavouriteData *favData=[[SharedObjects sharedInstance] favouriteData];
NSRange match = [urlString rangeOfString:string];
if ([string isEqualToString:@"search.htm"]) {
if (match.location!=NSNotFound) {
NSString *url=[NSString stringWithString:@"url............"];
NSData *data1=[NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
NSString *response=[[NSString alloc]initWithData:data1 encoding:nil];
SBJsonParser *parser=[SBJsonParser new];
NSDictionary *root = [Webview parser:string];
NSDictionary *elements = [[root objectForKey:@"SearchList"] lastObject];
NSArray *headlines = [elements objectForKey:@"HeadLinesNewsIds"];
NSArray *newstext=[element objectForKey:@"NewsTextNewsIds"];
NSArray *issuersnews=[element objectForKey:@"IssuersNewsIds"];
我的班级是Webview。