JSON Parsing in iOS 7

前端 未结 14 2275
长情又很酷
长情又很酷 2020-12-04 11:25

I am creating an app for as existing website. They currently has the JSON in the following format :

[

   {
       \"id\": \"value\",
       \"array\": \"[{\         


        
14条回答
  •  一个人的身影
    2020-12-04 12:11

    @property NSMutableURLRequest * urlReq;

    @property NSURLSession * session;

    @property NSURLSessionDataTask * dataTask;

    @property NSURLSessionConfiguration * sessionConfig;

    @property NSMutableDictionary * appData;

    @property NSMutableArray * valueArray; @property NSMutableArray * keysArray;

    • (void)viewDidLoad { [super viewDidLoad]; self.valueArray = [[NSMutableArray alloc]init]; self.keysArray = [[NSMutableArray alloc]init]; self.linkString = @"http://country.io/names.json"; [self getData];

    -(void)getData
    { self.urlReq = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:self.linkString]];

    self.sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
    
    self.session = [NSURLSession sessionWithConfiguration:self.sessionConfig];
    
    self.dataTask = [self.session dataTaskWithRequest:self.urlReq completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        self.appData = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    
        NSLog(@"%@",self.appData);
        self.valueArray=[self.appData allValues];
        self.keysArray = [self.appData allKeys];
    
    
    }];
    [self.dataTask resume];
    

提交回复
热议问题