gpt4 book ai didi

ios - 通过 JSON 获取 YouTube 用户的上传总数

转载 作者:行者123 更新时间:2023-11-29 03:35:22 24 4
gpt4 key购买 nike

我一直在尝试查找某个用户的上传总数,并找到了以下线程。

How can I retrieve the number of videos uploaded by a specific Youtube user?

当我从浏览器中点击 URL 时,这个问题的答案非常有效,但是当我进入 Obj-C 中点击以下 URL 时,它会为我返回 NULL。

https://gdata.youtube.com/feeds/api/users/megangore/uploads?v=2&alt=jsonc&max-results=0

我正在使用以下代码,有人可以告诉我我做错了什么吗?我要疯了。

NSString *URL = @"https://gdata.youtube.com/feeds/api/users/megangore/uploads?v=2&alt=jsonc&max-results=2";
NSLog(@"*******%@", URL);

dispatch_async(kBgQueue, ^{NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:URL]];
@autoreleasepool{
NSLog(@"******* PERFORMING STUFF *******");
[self performSelectorOnMainThread:@selector(processOrders:)withObject:data waitUntilDone:YES];
}
});

然后调用

//GOES TO SERVER AND LOOKS AT WORK ORDERS
-(void)processOrders:(NSData *)responseData
{

NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData //1

options:kNilOptions
error:&error];

//AMOUNT OF WORK ORDERS
NSArray* Orders = [json objectForKey:@"body"]; //2
NSDictionary* nextOrder = [Orders objectAtIndex:0];
NSString* TotalNumber = [nextOrder objectForKey:@"totalItems"];
NSLog(@"**********************************%@", TotalNumber);
}

还有:

#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) //1

答案在这里

NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData //1

options:kNilOptions
error:&error];

//AMOUNT OF WORK ORDERS
NSDictionary *returnedData = json[@"data"];
NSNumber *uploadCount = returnedData[@"totalItems"];
int value = [uploadCount intValue];
NSLog(@"loans: %i", value);

最佳答案

查看提供的链接的输出

 {"apiVersion":"2.1","data":{"updated":"2013-10-08T17:44:29.337Z","totalItems":115,"startIndex":1,"itemsPerPage":0}}

没有“body”键,也没有数组。如果上传的总项目数,

   NSDictionary *returnedData = json[@"data"];
NSNumber *uploadCount = returnedData[@"totalItems"];

关于ios - 通过 JSON 获取 YouTube 用户的上传总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19254085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com