Thursday, June 23, 2011

Json Parsing Request

NSDictionary *o1 = [NSDictionary dictionaryWithObjectsAndKeys:
                       
                        @"some value", @"key1",
                       
                        @"another value", @"key2",
                       
                        nil];
   
   
    NSDictionary *o2 = [NSDictionary dictionaryWithObjectsAndKeys:
                       
                        @"yet another value", @"key1",
                       
                        @"some other value", @"key2",
                       
                        nil];
   
   
    NSArray *array = [NSArray arrayWithObjects:o1, o2, nil];
   
   
    NSString *jsonString = [array JSONRepresentation];
   
    NSLog(@"%@",jsonString);
   
    NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://sample.com"]];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
   
    NSLog(@"%@",connection);



Note:

Before write code you have to include JSON Files. it is available

If you have any doubt ask me...

No comments:

Swift Operators - Basic Part 3 (Range operators in swift)

Range Operators: Closed Range operators  Half-Open Range Operators One-Sided Ranges Closed Range Operators:  a...b It defines...