我是 iphone 开发的新手。在这里我在执行我的代码时遇到问题
-[__NSCFString JSONValue]: unrecognized selector sent to instance 0x78e1000
2013-01-08 09:43:21.194 loanjson[655:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString JSONValue]: unrecognized selector sent to instance 0x78e1000'
*** First throw call stack:
(0x1c8d012 0x10cae7e 0x1d184bd 0x1c7cbbc 0x1c7c94e 0x2b34 0xbd0e59 0xbcef22 0xbd016a 0xbceedd 0xbcf055 0xb1c338 0x460aa81 0x4609d33 0x4647e3a 0x1c2f8fd 0x46484bc 0x4648435 0x45323a0 0x1c10f3f 0x1c1096f 0x1c33734 0x1c32f44 0x1c32e1b 0x1be77e3 0x1be7668 0x1265c 0x2322 0x2255)
libc++abi.dylib: terminate called throwing an exception
我不知道为什么会出现这个错误,我正在使用 JSON 请求和响应,我已经检查了要在 NSString 中解析的所有 JSON 值这是我的 .m 文件中的代码
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
self.responseData = nil;
NSArray* latestLoans = [(NSDictionary*)[responseString JSONValue] objectForKey:@"loans"];
[responseString release];
NSLog(@"%@",latestLoans);
//choose a random loan
NSDictionary* loan = [latestLoans objectAtIndex:0];
//fetch the data
NSNumber* fundedAmount = [loan objectForKey:@"funded_amount"];
NSNumber* loanAmount = [loan objectForKey:@"loan_amount"];
float outstandingAmount = [loanAmount floatValue] - [fundedAmount floatValue];
NSString* name = [loan objectForKey:@"name"];
NSLog(@"====:%@",(NSDictionary*)[loan objectForKey:@"location"]);
NSString* country = [(NSDictionary*)[loan objectForKey:@"location"] objectForKey:@"country"];
//set the text to the label
label.text = [NSString stringWithFormat:@"Latest loan: %@ from %@ needs another $%.2f, please help",
name,country,outstandingAmount
];
}
请指导我,谢谢