objective c - AFJSONRequestSerializer POST JSON Array -


I am trying to post to the API which is expecting the JSON array as input, for example For: [["token": "bd3", "display_order": 0}] I get the AFJSONRequestSerializer to get this build up: Unable to create parameter, my code:

  NSDictionary * campParams = @ {@ "token": @ "bd3", @ "display_order": @ "0"}; NSArray * arr = [NSArray arrayWithObject: campParams]; NSDictionary * Final = [object with NSDictionary dictionary: arr forKey: @ ""];   

that creates JSON:

  {"": [{"token": "bd55", "display_order": "0"}]}   

How do I modify my code to get the proper JSON output? I am making a second dictionary as AFHTTPRequestOperationManager accept the parameter as a dictionary, not an array

  [keep the manager. Url parameter: Final success: ^ (AFHTTPRequestOperation * operation, id responseObject) {/ Done} failure: ^ (FTPTRAQ operation operation *, NSERR * error) {NSLog (@ "error:% @", error); }];    

The last dictionary does not add actions, the question tells if a JSON array is expected. .

  NSArray * jsonArray = @ [@ {@ "Tokens": @ "BD3", @ "Display_order": @ "0"}]; NSError * error; NSDTA * JSNETActa = [NSJSNASSArailization DatavidjisonAbject: JasonArere Option: 0Error: and Error]; NSLog (@ "String as JSNDTTA:% @", [[NSSTING ALLOC] Init Withdata: JSNET Encoding: NSTF 8 string encoding]);   

Output:

  as jsonData string: [["token": "bd3", "display_order": "0"}]   

There is a possibility that the last argument number should be, no string:

  NSArray * jsonArray = @ [@ {@ "token": @ "BD3 ", @" Display_order ": @ 0}];   

Production:

  jsonData as string: [{"token": "BD3", "display_order": 0}]  am  

which better matches your initial JSON example

here's an example but AFNetworking not use because I do not proficient in it :.

  NSMutableURLRequest * Request = [NSMutableURL request request withURL: url]; [Request set httpbb: jssadata]; [Set http system: @ "post"]; [NSURLConnection sendAsynchronousRequest: Request line: [NSOperationQueue currentQueue] completionHandler: ^ (NSURLResponse * reaction, NSData * data, NSError * connectionError) {if (connectionError) {NSLog (@ :, "Error% @" connectionError); } Other {Anselog (@ "data as a string:% @", [[Ansstiing Elok] Init Waitdeta: Data Encoding: Anstif 8 string encoding]); }}];   

Note: Use AFNetworking in all ways, it's great! I just knew old OSX / IOS methods and I did not have a test project that had already installed Air Force.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -