我想使用 JSON 格式而不是 XML 从 youtube api 加载数据。这是我的消息来源:
- (void) getFavoriteList{
NSString* rawUrl = CONNECTION_GET_FAVORITE_LIST;
NSURL *url = [NSURL URLWithString:rawUrl];
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:url];
//create request header
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[request addRequestHeader:@"Authorization" value:[@" Bearer " stringByAppendingString:[appDelegate userInfo].accessTokenYoutube ]];
[request addRequestHeader:@"X-GData-Key" value:[NSString stringWithFormat:@"key=%@",YOUTUBE_DEVELOPER_KEY]];
[request addRequestHeader:@"alt" value:@"json"];
[request addRequestHeader:@"v" value:@"2"];
[request setRequestMethod:@"GET"];
[request startAsynchronous];
//register callback blocks.
[request setCompletionBlock:^{
NSString* respondMessage = [request responseString];
ParseData *parseData = [[ParseData alloc] init];
NSMutableArray *arrPlaylistVideos = [parseData allocVideo:respondMessage];
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_GET_FAVORITE_VIDEOS_SUCCESS object:arrPlaylistVideos];
}];
[request setFailedBlock:^{
NSString* respondMessage = [[request error] localizedDescription];
[[NSNotificationCenter defaultCenter]postNotificationName:NOTIFICATION_GET_FAVORITE_VIDEOS_FAILED object:respondMessage];
}];
[request release];
}
我设置了 alt = json 但 Youtube 总是返回 xml 数据。我在这里犯了什么错误吗?
注意:请不要告诉我应该使用 Gdata-ObjectiveC-Client。它非常非常复杂,我讨厌使用它。
谢谢。