JSON Parsing in iOS 7

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

    -(void)responsedata
    {
    
        NSMutableURLRequest *request=[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:replacedstring]];
    
        [request setHTTPMethod:@"GET"];
        NSURLSessionConfiguration *config=[NSURLSessionConfiguration defaultSessionConfiguration];
        NSURLSession *session=[NSURLSession sessionWithConfiguration:config];
        NSURLSessionDataTask *datatask=[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            if (error) {
                NSLog(@"ERROR OCCURE:%@",error.description);
            }
            else
            {
                NSError *error;
                NSMutableDictionary *responseDict=[[NSMutableDictionary alloc]init];
                responseDict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
    
    
                if (error==nil)
                {
    
    
                 // use your own array or dict for fetching as per your key..  
    
    
                    _responseArray =[[NSMutableArray alloc]init];
    
                    _geometryArray=[[NSMutableArray alloc]init];
    
    
    
                    _responseArray=[responseDict valueForKeyPath:@"result"];
    
                    referncestring =[[_photosArray objectAtIndex:0]valueForKey:@"photo_reference"];
    
                    _geometryArray=[_responseArray valueForKey:@"geometry"];
                   // _locationArray=[[_geometryArray objectAtIndex:0]valueForKey:@"location"];
                    _locationArray=[_geometryArray valueForKey:@"location"];
                    latstring=[_locationArray valueForKey:@"lat"];
                    lngstring=[_locationArray valueForKey:@"lng"];
    
    
            coordinates = [NSMutableString stringWithFormat:@"%@,%@",latstring,lngstring];
    
    
    
    
                }
    
            }
    
            dispatch_sync(dispatch_get_main_queue(), ^
                          {
    
    
    
                             // call the required method here..
    
                          });
    
    
    
    
        }];
        [datatask resume];   //dont forget it
    
        }
    

提交回复
热议问题