iPhone通过POST发送Json数组
我需要通过 POST 将以下 JSON 数组 发送到我们的服务器:
task:{"id":"123","list":"456","done":1,"done_date":1305016383}
我尝试使用 JSON 库,但不知怎么的,我使用起来太愚蠢了它。我什至尝试自己建立 POST-String,但也失败了:
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]];
....
你能帮我吗? json'ed POST 字符串对我来说就足够了:)
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 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因此,这可能是也可能不是您要问的问题,但您的 JSON 字符串的格式不正确。 JSON 格式的“任务”数组看起来像这样:
我只是在处理类似的情况发布到 PHP 服务器,我在网上找不到任何关于它的问题,但这就是我必须做的如果我发布相同的数据:
祝你好运!
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:
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:
Good luck!
这就是我处理它的方式:
我的 json 是一个看起来像这样的字符串
{"user":1337,"title":"某些标题","itemKeys":[1,1,1,1,1]}
This is how I handle It:
My json is a string that looks like this
{"user":1337,"title":"Some title","itemKeys":[1,1,1,1,1]}
我想问题不在于方法,而在于您尝试发布的字符串。试试这个:
换句话说:尝试使用引号。
您使用什么 JSON 库?
I suppose the problem is not with the methods, but with the string you're trying to post. Try this one:
In other words: experiment with the quotation marks.
What JSON library are you using?