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=%@¶ms=%@",PRE_URL,SEARCH_RESULT,self.token, jsonString];
// // url转码
NSCharacterSet *set = [NSCharacterSet URLQueryAllowedCharacterSet];
urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:set];
这样将字典转成string,再拼接到urlStr。然后转码。无法显示网页。
如下写死在里面在进行转码。就可以了。
NSString *usrStr = [NSString stringWithFormat:@"%@%@?token=%@¶ms={metaEntityTypeId:36,specialtyTypeId:49,equipmentModelId:163255,equipmentVendorId:10,entityTypeIds:[36073,36060]}",PRE_URL,SEARCH_RESULT,_usertoken];
请问。我怎么把字典放到url中才行呢
试着把NSJSONWritingPrettyPrinted改为0(是的没错改为0)
因为你这样的话编码出来的json是带换行符的,我怀疑是换行符的问题。