webview 加载网页问题

webview加载url 。需要传一个字典带过去。
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithCapacity:0];

[params setValue:@(36) forKey:@"metaEntityTypeId"];
[params setValue:@(49) forKey:@"specialtyTypeId"];
[params setValue:@[@(36073),@(36060)] forKey:@"entityTypeIds"];
[params setValue:@(163255) forKey:@"equipmentModelId"];
[params setValue:@(10) forKey:@"equipmentVendorId"];

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData                                                 encoding:NSUTF8StringEncoding];

NSString *urlStr = [NSString stringWithFormat:@"%@%@?token=%@&params=%@",PRE_URL,SEARCH_RESULT,self.token, jsonString];

// // url转码

NSCharacterSet *set = [NSCharacterSet URLQueryAllowedCharacterSet];
urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:set];

这样将字典转成string,再拼接到urlStr。然后转码。无法显示网页。

如下写死在里面在进行转码。就可以了。
NSString *usrStr = [NSString stringWithFormat:@"%@%@?token=%@&params={metaEntityTypeId:36,specialtyTypeId:49,equipmentModelId:163255,equipmentVendorId:10,entityTypeIds:[36073,36060]}",PRE_URL,SEARCH_RESULT,_usertoken];

请问。我怎么把字典放到url中才行呢

阅读 4.1k
1 个回答

试着把NSJSONWritingPrettyPrinted改为0(是的没错改为0)
因为你这样的话编码出来的json是带换行符的,我怀疑是换行符的问题。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题