{"code":,"message":"楠岃瘉鐮侀敊璇\xAF","developerMessage":"楠岃瘉鐮侀敊璇\xAF"}
上面是乱码,我是这样取值的:
web_reg_save_param("CodeDes",
"LB={\"message\":\"",
"RB=\"}",
"Ord=1",
LAST);
,然后是这样用函数转换的,
lr_convert_string_encoding(lr_eval_string("CodeDes"),
LR_ENC_UTF8,
LR_ENC_SYSTEM_LOCALE,
"str1"); // strcpy(message,lr_eval_string("{str1}")); // lr_save_string(message,"message1"); // lr_output_message("返回的描述为:%s",lr_eval_string("str1")); // lr_output_message(lr_eval_string("CodeDes")); lr_log_message("乱码的中文是:%s",lr_eval_string("{str1}"));
可是结果是没有取到值。
loadrunner输出log中的乱码解决
loadrunner做测试的时候,发现log里面的返回值有乱码,解决的方法很简单,先用notepad++打开,先转成utf-8格式,在转换成ANSI格式,就能变成正常的了。
{"shoppingCarts":[{"message":"闈炲父鎶辨瓑锛岄儴鍒嗗晢鍝佸敭缃勬垨涓嬫灦锛屾殏鏃舵棤娉曡喘
Action.c(15): 涔\xB0","addPriceProducts":[],"cart_type":1,"cart_id":1,"cart_name":"鏅\x80氳鍗\x95","
Action.c(15): cart_proTotalNum":{"value":"14浠\xB6","key":"鍟嗗搧鏁伴噺"},"cart_totalPrice":{"value":"17
Action.c(15): 22.80","key":"鎬婚噾棰濓紙涓嶅惈杩愯垂锛\x89"},"cart_favourableAmout":{"value":"0.0","key"
Action.c(15): :"浼樻儬"},"cart_totalIntegral":{"value":"1719.0","key":"鍟嗗搧绉垎"},"cart_totalWeight"
Action.c(15): :{"value":"5.996kg","key":"鍟嗗搧閲嶉噺"},"cart_products":[{"sellCount":116,"pro_id":52582
Action.c(15): 6,"pro_name":"鍚夊姏璐濅粈閿﹀彛鍛崇硸鏋\x9C(杩涘彛椋熷搧 鐩掕30g)","pro_pic_url":"http:
Action.c(15): //pic.womai.com/upload/601/603/606/525826_1_phone60_4610.JPG","pro_count":1,"pro_weight":{
Action.c(15): "value":"0.035kg","key":"閲嶉噺"},"pro_integral":{"value":"6.0","key":"绉垎"},"ptype":0,
Action.c(15): "price1":{"value":"6.3","key":"VIP浠\xB7"},"price2":{"value":"","key":""},"stock":0,"promo
Action.c(15): tion_tag":[]},{"sellCount":29,"pro_id":525829,"pro_name":"鍚夊姏璐濇煈姗樻贩鍚堝彛鍛崇硸鏋
Action.c(15): \x9C(杩涘彛椋熷搧 鐩掕100g)","pro_pic_url":"http://pic.womai.com/upload/601/603/606/5258
Action.c(15): 29_1_phone60_3224.JPG","pro_count":1,"pro_weight":{"value":"0.105kg","key":"閲嶉噺"},"pro_
Action.c(15): integral":{"value":"18.0","key":"绉垎"},"ptype":0,"price1":{"value":"18.3","key":"VIP浠\xB7
Action.c(15): "},"price2":{"value":"","key":""},"stock":0,"promotion_tag":[]},{"sellCount":819,"pro_id":
Action.c(15): 510055,"pro_name":"Nestle闆\x80宸㈢墝鑻卞紡鑽夎帗鍛冲啿楗矇300g(鑻卞浗杩涘彛 鐩\x92)","p
Action.c(15): ro_pic_url":"http://pic.womai.com/upload/601/603/606/6300/6302/6308/510055_1_phone60_4283.
Action.c(15): jpg","pro_count":1,"pro_weight":{"value":"0.3kg","key":"閲嶉噺"},"pro_integral":{"value":"
Action.c(15): 54.0","key":"绉垎"},"ptype":0,"price1":{"value":"54.9","key":"VIP浠\xB7"},"price2":{"val
Action.c(15): ue":"","key":""},"stock":0,"promotion_tag":[]},{"sellCount":559,"pro_id":510056,"pro_name"
Action.c(15): :"Nestle闆\x80宸㈢墝鑻卞紡棣欒晧鍛冲啿楗矇300g(鑻卞浗杩涘彛 鐩\x92)","pro_pic_url":"http
Action.c(15): ://pic.womai.com/upload/601/603/606/6300/6302/6308/510056_1_phone60_8347.jpg","pro_count":
Action.c(15): 1,"pro_weight":{"value":"0.3kg","key":"閲嶉噺"},"pro_integral":{"value":"54.0","key":"绉
Action.c(15): 垎"},"ptype":0,"price1":{"value":"54.9","key":"VIP浠\xB7"},"price2":{"value":"","key":""},
Action.c(15): "stock":0,"promotion_tag":[]},{"sellCount":43,"pro_id":503777,"pro_name":"绾ぉ鐒惰繘鍙i
Action.c(15): 樋鑱旈厠鐨囧啝妞版灒Fard绯诲垪(绀肩洅瑁\x85 1000g)","pro_pic_url":"http://pic.womai.com/up
Action.c(15): load/601/603/606/7300/7303/503777_1_phone60_1586.jpg","pro_count":1,"pro_weight":{"value":
Action.c(15): "1.0kg","key":"閲嶉噺"},"pro_integral":{"value":"59.0","key":"绉垎"},"ptype":0,"price1":
Action.c(15): {"value":"59.0","key":"VIP浠\xB7"},"price2":{"value":"","key":""},"stock":0,"promotion_tag
Action.c(15): ":[]},{"sellCount":246,"pro_id":503775,"pro_name":"DATE CROWN绾ぉ鐒剁殗鍐犳ぐ鏋ard绯诲
Action.c(15): 垪250g锛堥樋鑱旈厠杩涘彛 琚嬶級锛堟柊鏃у寘瑁呮洿鎹腑...锛\x89 ","pro_pic_url":"http://
Action.c(15): pic.womai.com/upload/601/603/606/7300/7303/503775_1_phone60_9626.JPG","pro_count":1,"pro_w
Action.c(15): eight":{"value":"0.25kg","key":"閲嶉噺"},"pro_integral":{"value":"19.0","key":"绉垎"},"p
Action.c(15): type":0,"price1":{"value":"19.1","key":"VIP浠\xB7"},"price2":{"value":"","key":""},"stock"
Action.c(15): :0,"promotion_tag":[]},{"sellCount":217,"pro_id":503776,"pro_name
另外网上发现一种方法,直接在loadrunner里面转码
http://bbs.51testing.com/thread-469065-1-1.html
我尝试了一下,也是可以用的,特别是当返回值是乱码,却要作为参数的时候
Action(){
// char *token;
// char temp[100];
// lr_convert_string_encoding(lr_eval_string("{RoomName}"),"utf-8",NULL,"myroom");//将utf-8转成系统当前的编码
// strcpy(temp,lr_eval_string("{myroom}"));//取出参数值,并且赋值给变量temp
// token=(char *)strtok(temp,"<");//使用<符号作为分隔符
// lr_error_message(token);
char *token;
char temp[100];
// lr_output_message ({id});
web_add_header("Appkey","9988986");
web_add_header("Mid","0");
web_add_header("Udid","AB:CD:EH:JH");
web_add_header("Unique","AB:CD:EH:JH");
web_add_header("Sourceid","3");
web_add_header("Os","ios");
web_add_header("Appversion","2.0");
web_add_header("Userid","140422");
web_add_header("Usersession","login");
web_add_header("charset","UTF-8");
web_submit_data("submit",
"Action=http://XXXXXX",
"Method=GET",
"RecContentType=application/json",
"Referer=http://XXXXX",
"Mode=html",
ITEMDATA,
//"Name=data", "Value=\[{\"skuId\":\"525827\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"525826\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"525829\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"533855\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"510055\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"510056\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"518610\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"508014\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"503777\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"503775\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"503776\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"540294\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"522182\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"556648\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"525021\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"515744\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"510517\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"510792\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"510794\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"76806\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"502805\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"76804\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"76800\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"535881\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"535880\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"511142\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"554869\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"545703\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"292675\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"515304\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"553231\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"}\]", ENDITEM,
"Name=data", "Value=\[{\"skuId\":\"525827\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"525826\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"525829\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"533855\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"510055\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"510056\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"518610\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"508014\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"503777\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"503775\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"503776\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"540294\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"522182\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"556648\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"525021\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"515744\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"510517\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"510792\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"510794\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"76806\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"502805\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"76804\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"76800\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"535881\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"535880\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"511142\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"554869\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"545703\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"292675\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"515304\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"},{\"skuId\":\"553231\",\"amount\":\"1\",\"productType\":\"0\",\"type\":1,\"classType\":\"1\"}\]", ENDITEM,
LAST);
//
web_add_header("Appkey","9988986");
web_add_header("Mid","0");
web_add_header("Udid","AB:CD:EH:JH");
web_add_header("Unique","AB:CD:EH:JH");
web_add_header("Sourceid","3");
web_add_header("Os","ios");
web_add_header("Appversion","2.0");
web_add_header("Userid","140422");
web_add_header("Usersession","login");
web_add_header("charset","UTF-8");
web_reg_save_param("id",
"LB=price",
"RB=pic",
"Search=body",
LAST);
web_submit_data("address",
"Action=http://XXXXX",
"Method=POST",
"RecContentType=application/json",
"Referer=XXXXXX",
"Mode=HTTP",
ITEMDATA,
//"Name=data", "Value={\"address\":\"12306\",\"couponcard\":\[\"100\",\"200\"\],\"cartId\":\"10086\",\"payway\":{\"amount\":\"100.2\",\"other\":\"1\"},\"express_time\":{\"delivery_id\":\"0\",\"segment_id\":\"0\"}}", ENDITEM,
"Name=data",
"Value={\"address\":\"{regionid}\",\"cartId\":\"1\",\"couponcard\":[],\"payway\":{\"amount\":\"\",\"other\":\"200\"},\"express_time\":{\"delivery_id\":\"0\",\"segment_id\":\"0\"}}",ENDITEM,
//"Value={\"address\":\"0\",\"couponcard\":[],\"cartId\":\"1\",\"payway\":{\"amount\":\"\",\"other\":\"1\"},\"express_time\":{\"delivery_id\":\"0\",\"segment_id\":\"0\"}}", ENDITEM,
LAST);
lr_convert_string_encoding(lr_eval_string("{id}"),"utf-8",NULL,"my");
// strcpy(temp,lr_eval_string("{my}"));//取出参数值,并且赋值给变量temp
// token=(char *)strtok(temp,"<");//使用<符号作为分隔符
lr_message ("value: %s",lr_eval_string("{my}"));
return 0;
}
LoadRunner脚本开发-字符串编码转换
相关函数
lr_convert_string_encoding函数
功能:字符串编码转换
原型:
int lr_convert_string_encoding(const char *sourceString, const char *fromEncoding, const char *toEncoding, const char *paramName);
返回值:0(执行成功)、-1(执行失败)
参数说明:
sourceString:要转换的字符串
fromEncoding:源字符的编码
toEncoding:保存在参数parmaName中的字符串编码,即要转换的目标编码
paramName:保存转换编码后的字符串
说明:
1.lr_convert_string_encoding支持system locale,Unicode,UTF-8字符串编码的相互转换,参数paramName中保存结果字符串,该结果字符串包含字符串结束符NULL
2.结果字符串中的可打印字符在VuGen和日志中按实际字符显示,不可打印字符则以十六进制显示,例如:
rc = lr_convert_string_encoding("A", NULL, LR_ENC_UTF8, "stringInUnicode");
结果字符串(即stringInUnicode参数值)显示为:A\x00, 而不是\x41\x00,因为A为可打印字符串.
3.fromEncoding and toEncoding可选值:
loadrunner <wbr>脚本开发-字符串编码转换
例子:
Action()
{
int rc = 0;
char *converted_buffer_unicode = NULL;
rc = lr_convert_string_encoding("hello", NULL, LR_ENC_UNICODE, "stringInUnicode");
if(rc < 0)
{
lr_output_message("convert_string_encoding failed ");
// error
}
return 0;
}
|
输出结果: