jsonkit

 

 

 

//#define kDoubanUrl      @"http://douban.fm/j/mine/playlist?type=n&h=&channel=0&from=mainsite&r=4941e23d79"

//jsonkit

NSString* strUrl=kDoubanUrl; //it return json format string

    

    NSURL *url=[NSURL URLWithString:strUrl];

NSMutableURLRequest  *request=[[NSMutableURLRequest alloc] initWithURL:url];      

    NSError *err=nil;    

    NSData *jsonData=[NSURLConnection sendSynchronousRequest:request

  returningResponse:nil

  error:&err];

    NSDictionary *resultsDictionary = [jsonData objectFromJSONData];

NSLog(@"resultsDictionary=%@  \n  %@", resultsDictionary,[resultsDictionary objectForKey:@"r"]);

NSMutableArray *songs = [resultsDictionary objectForKey:@"song"];

NSLog(@"  songs  %@ \n  0000000000  %@",songs,[songs objectAtIndex:0]);

for (int i=0; i<[songs count]; i++) {

NSDictionary *dic = [songs objectAtIndex:i ];

//NSLog(@"dic=%@", dic );

NSString *jsonTextStr = @":";  

jsonTextStr = [jsonTextStr stringByAppendingString:[dic objectForKey:@"title"]];  

jsonTextStr = [jsonTextStr stringByAppendingString:@"\n"]; 

jsonTextStr = [jsonTextStr stringByAppendingString:[dic objectForKey:@"url"]]; 

NSLog(@"信息:%@",jsonTextStr);  

}