I need to send the following JSON array via POST to our server:
task:{"id":"123","list":"456","done":1,"done_date":1305016383}
I tried with the JSON library, but I was somehow to stupid to use it. I even tried to build up the POST-String by myself, but also failed:
NSString *post = @"task='{id:123,list:456,done:1,done_date:1305016383}'";
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:30];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[post dataUsingEncoding:NSUTF8StringEncoding]];
....
Can you please help me? The json’ed POST string would be even enough for me :)
So this may or may not be the question you are asking, but your JSON string is not formed correctly. An array of "task" in JSON format would look like this:
NSString *post = @"{"task":[{"id":"123","list":"456","done":1,"done_date":1305016383}]}";
I was just wresting with a similar situation posting to a PHP server and I couldn't find any questions about it online, but this is what I would've had to do if I were posting the same data:
NSString *post = @"task[0][id]=123&task[0][list]=456&task[0][done]=1&task[0][done_date]=1305016383&";
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:30];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[post dataUsingEncoding:NSUTF8StringEncoding]];
...
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With