我得到这样的回应:
2013-04-22 15:38:38:693 Some[963:3079] __36-[SDAFParseAPIClient getDataFromWeb]_block_invoke [Line 88] parsing
2013-04-22 15:38:38:694 Some[963:3079] -[SDAFParseAPIClient parser:didStartElement:namespaceURI:qualifiedName:attributes:] [Line 64] Element started string
2013-04-22 15:38:38:695 Some[963:3079] -[SDAFParseAPIClient parser:foundCharacters:] [Line 78] The characters are { "recordcount": "62", "data": [ { "Codigo": "1", "NombrePublico": "Super Stor
2013-04-22 15:38:38:696 Some[963:3079] -[SDAFParseAPIClient parser:foundCharacters:] [Line 80] The page numbers are (null)
2013-04-22 15:38:38:698 Some[963:3079] -[SDAFParseAPIClient parser:foundCharacters:] [Line 78] The characters are es", "Horario": "LV:8:00 AM - 6:30 PM,S:8:00 AM - 5:00 PM,D:-", "Direccion": "6 Ave., 5 Calle, S.O. Bo. El", "Telefono": "2556-1242", "Coordenadas": "16.502917616794166,-85.02710920572281", "Ciudad": "SAN PEDRO SULA" }, { "Codigo": "2", "NombrePublico": "Some 3 Ave.", "Horario":
2013-04-22 15:38:39.571 Some[963:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
这是我的代码:
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
NSLog(@"Element started %@",elementName);
self.currentElement=elementName;
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
NSLog(@"Element ended %@",elementName);
self.currentElement=@"";
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if([self.currentElement isEqualToString:@"string"]){
NSLog(@"The characters are %@",string);
id data = [NSJSONSerialization JSONObjectWithData:[string dataUsingEncoding:NSASCIIStringEncoding] options:0 error:nil];
NSLog(@"The page numbers are %@",[[[data valueForKey:@"List"] objectAtIndex:0] valueForKey:@"PageNumber"]);
}
}
-(void)getDataFromWeb{
NSURL *feedURL = [[NSURL alloc] initWithString:@"http://someserver.com?Cli_Cod=1&Key_String=34uhg934hg389j"];
NSURLRequest *feedRequest = [[NSURLRequest alloc] initWithURL:feedURL];
AFXMLRequestOperation *feedOperation = [AFXMLRequestOperation XMLParserRequestOperationWithRequest:feedRequest success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser) {
NSLog(@"parsing");
[XMLParser setDelegate:self];
[XMLParser parse];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser) {
UIAlertView *connectionError = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
[connectionError show];
}];
[feedOperation start];
}
谢谢