I am new to objective-c and I need to send a collection of json objects.
I wrote the following:
NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjectsAndKeys: id, @"id", toClientGroupType, @"toClientGroupType", dueDate, @"dueDate", actionDate, @"actionDate", campaignType, @"campaignType", campaignCategory, @"campaignCategory", businessId, @"businessId", promotion, @"promotion", product, @"product", contentF, @"content", subject, @"subject", nil]; NSData *jsonData2 = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:NSJSONWritingPrettyPrinted error:&error]; NSString *jsonString = [[NSString alloc] initWithData:jsonData2 encoding:NSUTF8StringEncoding]; NSLog(@"jsonData as string:\n%@", jsonString); [request setURL:[NSURL URLWithString:@"https://services-dev.a.com/api/channels"]]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:jsonData2];
I have 2 problems:
a. JsonData result as String -
{ "toClientGroupType" : "VIP", "id" : "1", "dueDate" : "2012-09-03 10:25:42 +0000", "actionDate" : "2012-09-03 10:25:42 +0000", "campaignType" : "ONE_TIME", "businessId" : "150", "campaignCategory" : "SALE" }
As you can see, I am missing 3 fields that I declared: content , product and subject
B. I really need to represent an array of objects, so the query would be like this:
[{ "toClientGroupType" : "VIP", "id" : "1", "dueDate" : "2012-09-03 10:25:42 +0000", "actionDate" : "2012-09-03 10:25:42 +0000", "campaignType" : "ONE_TIME", "businessId" : "150", "campaignCategory" : "SALE" }]
How can I do this and what is wrong?