【发布时间】:2011-11-18 06:35:16
【问题描述】:
我正在尝试做一些看起来很简单的事情,但由于某种原因不起作用。
我正在尝试对 JSON 数据发出 get 请求,在 URL 中发送 JSON 'data' 参数。
这是我正在使用的代码:
NSDictionary *whatToPost= [NSDictionary dictionaryWithObjectsAndKeys:
username, @"username",
password, @"password", nil];
NSString *url = [NSString stringWithFormat:@"http://domain.com/user/get?data=%@",
[whatToPost JSONString]];
NSURL *theUrl = [NSURL URLWithString:
[url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//NSLog(url) will produce this:
http://domain.com/user/get?data={"username":"test1","password":"poop"}
当我设置断点时,theUrl 为空。我不太明白它为什么会中断,但我想发送 {'s 或 "'s 会破坏它。有什么想法吗?我应该切换到 POST 吗?
【问题讨论】:
标签: iphone objective-c json nsurl