BZForursquare を使用して近くの会場を UITableView に取得している間、私は今本当に立ち往生しています。
BZFoursquare: https://github.com/baztokyo/foursquare-ios-api
requestDidFinishLoading デリゲート メソッド内で Requestresult を取得します。このメソッドでは、リクエスト オブジェクトに複数の NSDictionaries が含まれており、1 つのディクショナリが request.response にあります。この応答ディクショナリには、key="venues" を含む 1 つのエントリが含まれ、値として JSON オブジェクトが含まれます。この値オブジェクトをディクショナリに入れると、型はディクショナリではなく NSCFArray のようです。
#pragma mark BZFoursquareRequestDelegate
- (void)requestDidFinishLoading:(BZFoursquareRequest *)request {
self.meta = request.meta;
self.notifications = request.notifications;
self.response = [request.response objectForKey:@"venues"];
self.request = nil;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSLog(@"%@",[self.response objectForKey:@"name"]);
}
NSLog Line で次のエラーが表示されるため、これを想定しています。
-[__NSCFArray objectForKey:]: 認識されないセレクターがインスタンス 0x1e5c90f0 に送信されました
今、私は完全に混乱しており、この JSON をデータ型から NSDictionary に取得しようとして失敗しました。1 つの試みは、値 Object を NSString に入れて使用することでした。
[NSJSONSerialization JSONObjectWithData:[responseString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error];
それをディクショナリに入れることはできますが、まだ NSCFArray のままであるため、これも失敗しました。誰かがコンテンツを取得する方法を教えてください
[request.response objectForKey:@"venues"]
UITabelview にこのコンテンツを入力できるように、NSDictionary に変換しますか?
編集:
ディクショナリ request.response の値部分の内容は次のとおりです。
(
{
categories = (
{
icon = {
name = ".png";
prefix = "https://foursquare.com/img/categories/food/default_";
sizes = (
32,
44,
64,
88,
256
);
};
id = 4bf58dd8d48988d10b941735;
name = "Falafel Restaurant";
pluralName = "Falafel Restaurants";
primary = 1;
shortName = Falafel;
}
);
contact = {
};
hereNow = {
count = 0;
groups = (
);
};
id = 4df3489dfa76abc3d86c4585;
likes = {
count = 0;
groups = (
);
};
location = {
cc = DE;
city = "Vinn";
country = Germany;
distance = 92;
lat = "51.44985";
lng = "16.648693";
state = "Nordrhein-Westfalen";
};
name = "Yildiz D\U00f6ner";
specials = (
);
stats = {
checkinsCount = 3;
tipCount = 0;
usersCount = 2;
};
verified = 0;
}
そして、これは NSCFArray の Type からのようです。また、キーで JSON 値にアクセスできるように、この別のディクショナリから作成するにはどうすればよいでしょうか? 今日は本当に遅くてすみません…