Spi*_*idy 0 json namespaces nsurl nsdata ios
我试图请求以下URL,我收到一个错误,说"数据参数是零".我发现'seller_name'有空格,'amount'有点(.).我认为这是由URL引起的问题.那么有没有办法发送有空格和点的URL而不丢失信息?
NSURL *url1 = [[NSURL alloc]initWithString:[NSString stringWithFormat:@"192.168.1.85/localex_postsale.html?contactid=%@&exchangeid=%@&token=%@&buyerid=%@&seller_name=%@&desc=%@&amount=%@&sellerid=%@",contactid,exchangeid,token,buyervalue,sellers,_Description,_Amount,contactid]];
NSError *errors1;
NSData *data1 = [NSData dataWithContentsOfURL:url1];
NSDictionary *json1 = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:data1 options:kNilOptions error:&errors1];
Run Code Online (Sandbox Code Playgroud)
看一下-stringByAddingPercentEscapesUsingEncoding:方法NSString,例如:
NSString *myUnencodedString = [NSString stringWithFormat:@"192.168.1.85/localex_postsale.html?contactid=%@&exchangeid=%@&token=%@&buyerid=%@&seller_name=%@&desc=%@&amount=%@&sellerid=%@",contactid,exchangeid,token,buyervalue,sellers,_Description,_Amount,contactid]
NSString *encodedString = [myUnencodedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *myURL = [[NSURL alloc] initWithString:encodedString]
...
Run Code Online (Sandbox Code Playgroud)
Cf.:Apple 文档.
| 归档时间: |
|
| 查看次数: |
1770 次 |
| 最近记录: |