Ios NSMutableData到NSDictionary返回null

Ios NSMutableData到NSDictionary返回null,ios,objective-c,nsdictionary,nsmutabledata,Ios,Objective C,Nsdictionary,Nsmutabledata,我正在编写一个使用Instagram API的程序,但在NSMutableData和NSDictionary方面遇到了一些问题。 因为我必须对API进行多次调用,所以我决定创建一个NSMutableData对象,将较小的NSData对象附加到该对象中,然后将整个过程转化为一个NSDictionary 但是,在我第二次调用NSMutableData appendData NSData之后,当我将NSMutableData转换为NSDictionary时,字典返回null 这是我的一些代码 NSMu

我正在编写一个使用Instagram API的程序,但在
NSMutableData和NSDictionary方面遇到了一些问题。

因为我必须对API进行多次调用,所以我决定创建一个
NSMutableData对象
,将较小的NSData对象附加到该对象中,然后将整个过程转化为一个NSDictionary

但是,在我第二次调用
NSMutableData appendData NSData之后,
当我将
NSMutableData
转换为
NSDictionary
时,字典返回null

这是我的一些代码

NSMutableData *userData = [[NSMutableData alloc]init]
NSData *feed = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString   stringWithFormat:@"https://api.instagram.com/v1/users/17636367/media/recent?access_token=%@",accessToken]]];
[userData appendData:feed];
NSData *moarData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.instagram.com/v1/users/17636367/media/recent?access_token=%@&max_id=%@",accessToken, maxID]]];
[userData appendData:moarData];
NSDictionary *dictTwo = [NSJSONSerialization JSONObjectWithData:userData options:NSJSONReadingMutableContainers error:nil];
NSLog(@"%@",dictTwo);
dictTwo返回null。但是,当我只调用一次appendData时,字典不是空的


谢谢。

第一次调用将返回数组或字典。假设它是一本字典,你会得到如下结果:

{"some":"data"}
这可以正确解析。当你打两个电话时,你会得到:

{"some":"data"}{"other":"data"}

这不是有效的JSON。您需要分别解析每个项目。

当您附加两个单独的JSON响应时,它们不会形成JSON

您可以通过以下链接测试最终结果,查看它是否为JSON:


您需要分别解析每个查询响应,然后对该数据应用操作:(例如NSMutableDictionary、NSMutableArray等)。

检查accesstoken是否为零。