ios - webview 加载网页问题
天蓬老师
天蓬老师 2017-04-17 17:10:03
[iOS讨论组]

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中才行呢

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复(1)
怪我咯

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号