JSON Parsing in iOS 7

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

    //-------------- get data url--------
    
    NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://echo.jsontest.com/key/value"]];
    
    NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSLog(@"response==%@",response);
    NSLog(@"error==%@",Error);
    NSError *error;
    
    id jsonobject=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
    
    if ([jsonobject isKindOfClass:[NSDictionary class]]) {
        NSDictionary *dict=(NSDictionary *)jsonobject;
        NSLog(@"dict==%@",dict);
    }
    else
    {
        NSArray *array=(NSArray *)jsonobject;
        NSLog(@"array==%@",array);
    }
    

提交回复
热议问题