JSON Parsing in iOS 7

前端 未结 14 2240
长情又很酷
长情又很酷 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:10

    May be this will help you.

    - (void)jsonMethod
    {
        NSMutableArray *idArray = [[NSMutableArray alloc]init];
        NSMutableArray *nameArray = [[NSMutableArray alloc]init];
        NSMutableArray* descriptionArray = [[NSMutableArray alloc]init];
    
        NSHTTPURLResponse *response = nil;
        NSString *jsonUrlString = [NSString stringWithFormat:@"Enter your URL"];
        NSURL *url = [NSURL URLWithString:[jsonUrlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    
    
        NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
        NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
    
        NSDictionary *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"Result = %@",result);
    
    
        for (NSDictionary *dic in [result valueForKey:@"date"])
        {
            [idArray addObject:[dic valueForKey:@"key"]];
            [nameArray addObject:[dic valueForKey:@"key"]];
            [descriptionArray addObject:[dic valueForKey:@"key"]];
    
        }
    
    }
    

提交回复
热议问题