我是objective-c的新手,需要提交一组json对象。
我写了以下内容:
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];
我有两个问题:
A. 将jsonData输出为字符串时的结果是:
{
"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"
}
您看到了吗 - 我缺少了三个我声明的字段:content
,product
和subject
B. 实际上我需要提交一个对象数组,因此请求将是这样的:
[{
"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"
}]
我应该怎么做?有什么问题吗?