先来认识下lr_convert_string_encoding:
int lr_convert_string_encoding( const char *sourceString, const char *fromEncoding,const char *toEncoding, const char *paramName);
官方参数解释:
sourceString:The string to convert
fromEncoding :The encoding of the sourceString
toEncoding:The encoding to convert of the string saved in parameter paramName
paramName:The name of the parameter in which the destination string will be saved
中文参数解释:
sourceString:被转换的源字符串。
fromEncoding:转换前的字符编码。
toEncoding:要转换成为的字符编码。
paramName:转换后的目标字符串。
常量和值得关系:
Constant |
|
1、request乱码:将中文消息使用lr_convert_string_encoding先转码,再传入请求参数
注意:请求转码函数必须写在请求函数之前
1 //中文请求参数转换 2 lr_convert_string_encoding( "我是肖恩",LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8, "str" ); 3 lr_save_string(lr_eval_string("{str}"),"strvalue");
2、response乱码:将响应乱码lr_convert_string_encoding先转码,再输出(这样在lr的日志中就能看到正常的中文了)
注意:响应转换函数必须写在请求函数之后
1 //响应乱码转换 2 lr_convert_string_encoding(lr_eval_string("{value01}"), LR_ENC_UTF8,LR_ENC_SYSTEM_LOCALE,"BM"); 3 lr_error_message(lr_eval_string("{BM}"));
两种完整代码如下:
1 web_reg_save_param_ex( 2 "ParamName=value01", 3 "LB=,"msg":"", 4 "RB=,"data", 5 SEARCH_FILTERS, 6 LAST); 7 //中文请求参数转换 8 lr_convert_string_encoding( "我是肖恩",LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8, "str" ); 9 lr_save_string(lr_eval_string("{str}"),"strvalue"); 10 //下订单 11 web_custom_request("下订单", 12 "URL=http://192.168.145.130:8080/mobile/api/order/addorder", 13 "Method=POST", 14 "TargetFrame=", 15 "Resource=0", 16 "Referer=", 17 "Mode=HTML", 18 "EncType=application/json", 19 "Body={"token":"{get_token}","getAddrId":1,"getCarId":23,"payType":2,"remark":"{strvalue}","price":1,"orders":[{"getTime":"1450921104000","goodss":[{"goodsId":93,"count":1},{"goodsId":96,"count":1}]}],"invoiceTitle":"fapiao"}", 20 LAST); 21 //响应乱码转换 22 lr_convert_string_encoding(lr_eval_string("{value01}"), LR_ENC_UTF8,LR_ENC_SYSTEM_LOCALE,"BM"); 23 lr_error_message(lr_eval_string("{BM}"));
3、lr里面乱码设置:(此方法不一定能解决响应乱码问题,但是大部分都可以解决)
小白记录~~ 欢迎评论留言~~