Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate array of json objects in objective c
    primarykey
    data
    text
    <p>I am new to objective-c and need to submit collection of json objects.</p> <p>I wrote the following:</p> <pre><code>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:&amp;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]; </code></pre> <p>I have 2 problems:</p> <p>A. The output of jsonData as String is </p> <pre><code>{ "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" } </code></pre> <p>As you see - I am missing 3 fiels which I declared: <code>content</code>, <code>product</code> and <code>subject</code></p> <p>B. I actually need to submit an array of objects so the request will be like this:</p> <pre><code>[{ "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" }] </code></pre> <p>How can I do it and what is wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload