Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 将JSON转换为NSDictionary或NSArray-iOS_Iphone_Objective C_Ios_Ios5_Ios6 - Fatal编程技术网

Iphone 将JSON转换为NSDictionary或NSArray-iOS

Iphone 将JSON转换为NSDictionary或NSArray-iOS,iphone,objective-c,ios,ios5,ios6,Iphone,Objective C,Ios,Ios5,Ios6,我有一段代码: [self.vManager playersNearLocation:userLocation block:^(NSSet *players, NSError *error) { if(players && [players count]) { NSLog(@"Success in getting players");

我有一段代码:

[self.vManager playersNearLocation:userLocation
                             block:^(NSSet *players, NSError *error)
    {
        if(players && [players count])
        {
            NSLog(@"Success in getting players");
            /* TO DO
              Convert JSON to Objective C object here
            */   
        }else{
            NSLog(@"Failed to get players");
        }
    }];
我从服务器接收JSON,如何将其转换为字典或数组对象。我不想使用任何外部库,有本地方式吗


谢谢

如果您有SBJSON库,解析json非常容易:

在您的项目中包括这个库。导入json.h,您可以如下解析json

   SBJSON *parser=[[SBJSON alloc]init];

NSDictionary * dictionary = [parser objectWithString:responseString];

如果您有SBJSON库,解析json非常容易:

在您的项目中包括这个库。导入json.h,您可以如下解析json

   SBJSON *parser=[[SBJSON alloc]init];

NSDictionary * dictionary = [parser objectWithString:responseString];

尝试
NSJSONSerialization
和方法

+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error

尝试
NSJSONSerialization
和方法

+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error

请参阅此链接:-您的json数据是否存在于某个文档文件中或直接从服务器获取。请参阅此链接:-您的json数据存在于某个文档文件中或直接从服务器获取。请注意,我不想使用任何外部库,有本机方法吗?;-)请注意,我不想使用任何外部库,有本地方式吗?;-)