I have a wcf service which accepts a parameter like this:
[DataContract]
public class Person
{
[DataMember]
public int ID { get; set; }
[DataMem
Something like this code should work:
NSArray *propertyNames = [NSArray arrayWithObjects:@"ID", @"Name", @"Family", nil];
NSArray *propertyValues = [NSArray arrayWithObjects:@"123", @"joe", @"smith", nil];
NSDictionary *properties = [NSDictionary dictionaryWithObjects:propertyValues forKeys:propertyNames];
NSMutableDictionary* personObject = [NSMutableDictionary dictionary];
[personObject setObject:properties forKey:@"person"];
NSString *jsonString = [personObject JSONRepresentation];
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.0.217/JSON/Service1.svc/InsertPerson"]];
[request setValue:jsonString forHTTPHeaderField:@"json"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:jsonData];
NSError *errorReturned = nil;
NSURLResponse *theResponse =[[NSURLResponse alloc]init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&errorReturned];
if (errorReturned) {
//...handle the error
}
else {
NSMutableString *retVal = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//...do something with the returned value
[retVal release];
}
[theResponse release];