请求Json数据,并且解析Json数据

NSURLRequest*request=[NSURLRequestrequestWithURL:[NSURLURLWithString:@"https://api.douban.com/v2/book/search?tag=computer"]];

//将请求的url数据放到NSData对象中

NSData*response=[NSURLConnectionsendSynchronousRequest:requestreturningResponse:nilerror:nil];

//IOS5自带解析类NSJSONSerialization从response中解析出数据放到字典中

NSDictionary*weatherDic=[NSJSONSerializationJSONObjectWithData:responseoptions:NSJSONReadingMutableLeaveserror:&error];

NSArray*localdata=[weatherDicobjectForKey:@"books"];

相关推荐