我想从使用 MKLocalSearch 检索的这个 NSDictionary 中返回“star_rating”的值。在我将valueForKeyPath:@"business"应用到它之后,返回的字典看起来像这样。
UID = 8094514780070527910;
URL = "http://www.uvm.edu";
attribution = (
{
attributionURLs = (
"yelp5.3:///biz/university-of-vermont-burlington",
"yelp4:///biz/university-of-vermont-burlington",
"yelp:///biz/university-of-vermont-burlington",
"http://yelp.com/biz/university-of-vermont-burlington"
);
sourceIdentifier = "com.yelp";
sourceVersion = 1;
}
);
canBeCorrectedByBusinessOwner = 1;
name = "The University of Vermont";
source = (
{
"source_id" = 647659235;
"source_name" = "geo_id";
},
{
"source_id" = dBeQ7Nq1LcngfTz7gKrjLA;
"source_name" = yelp;
},
{
"source_id" = A3H0613898;
"source_name" = "acxiom_us";
},
{
"source_id" = A1L0080070;
"source_name" = "acxiom_us";
},
{
"source_id" = A3H0614039;
"source_name" = "acxiom_us";
},
{
"source_id" = "university-of-vermont-burlington";
"source_name" = "yelp_alias";
}
);
"star_rating" = (
"4.5"
);
telephone = "+18026563131";}
我的代码:
MKMapItem *firstMapItem = [response.mapItems objectAtIndex:0];
NSDictionary *bizdic = [firstMapItem valueForKeyPath:@"business"];
NSLog(@"%@", bizdic);
//Problem Occurs Here
NSLog(@"%@", [bizdic valueForKeyPath:@"\"star_rating\""]);
每次我将“star_rating”的值打印到控制台时,应用程序都会崩溃并产生以下错误:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<GEOBusiness 0x160c5f20> valueForUndefinedKey:]: this class is not key value coding-compliant for the key "star_rating".'
如果我使用像电话这样的值而不是“star_rating”,它会返回电话号码没有问题。这是我第一次使用 MKLocalSearch,因此感谢任何建议。