Solve json_encode Chinese UNICODE transcoding problem below PHP5.4

Solve json_encode Chinese UNICODE transcoding problem below PHP5.4

Urlencode the Chinese characters first and then use json_encode.
After json_encode, use urldecode again to decode,
so that the Chinese characters in the encoded json array will not be unicode encoded.

         $params['importList']['recipientAddress'] = urlencode("江苏省苏州市昆山市");
		 $params['importList']['salePrice'] = 245.0;
		 $params['importList']['salesModel'] = urlencode("内贸模式");
		 $params['importList']['shopNumber'] = "kd";
		 $params['importList']['totalAmount'] = 0.0;
		 var_dump($params);
		 //直接转码就会变成汉字就会变成\u****
		 var_dump(json_encode($params));
		 // 5.4以上加 JSON_UNESCAPED_UNICODE 可解决
		 //var_dump(json_encode($params, JSON_UNESCAPED_UNICODE));
		 
		 // 5.4以下 先把汉字用url编码,转为json后在用url解码,完美避开看字转unicode的问题
		 var_dump(urldecode(json_encode($params)));

Case screenshot

Demonstration case

operation result

result

Guess you like

Origin blog.csdn.net/gixome/article/details/131647672