gpt4 book ai didi

ios - 使用 AFNetworking 2.5 将 JSON 序列化为 NSArray

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:02:50 25 4
gpt4 key购买 nike

到目前为止,利用 AFNetworking 2.5 填充与顶级轨道相关的艺术家的数组以及 last.fm API 一直是一个挑战。这是我目前的代码。

NSURL *url = [NSURL URLWithString:URLstring];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

NSDictionary *dict = (NSDictionary *)responseObject;
NSArray *allValues = [dict allValues];
NSLog(@"all values contained in array: %@", allValues);
NSLog(@"all values count: %lu", allValues.count);

计数返回 1。我想要一个用轨道填充的数组,每个索引值对应一个轨道。目前,只有第一个索引值填充在数组中。我还注意到正在打印的 JSON 数据是 JSON 格式的,并且看起来不像 NSArray 中的对象在打印时会出现。

编辑:这里是 input

最佳答案

使用KVC获取轨道数组:

NSArray* tracks = [dict valueForKeyPath:@"toptracks.track"] 

或者类似的东西

关于ios - 使用 AFNetworking 2.5 将 JSON 序列化为 NSArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27284696/

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