decode_json 必须是unicode形式的字符

$response->decoded_content是字符
$response->content是字节

jrhmpt01:/root# perl x3.pl 307 0
$str is %E6%9D%AD%E5%B7%9E
$content is {"code":1000,"msg":"success!","data":{"buses":[{"busId":0,"station":-1,"state":-1,"distance":-1,"reporTime":-1}],"stations":[{"station":1,"stateName":"\u5218\u6587\u6751"},{"station":2,"stateName":"\u8584\u677f\u5206\u5382"},{"station":3,"stateName":"\u6bdb\u7af9\u5c71"},{"station":4,"stateName":"\u6c88\u5bb6\u6865"},{"station":5,"stateName":"\u7126\u5316\u5206\u5382"},{"station":6,"stateName":"\u676d\u73bb"},{"station":7,"stateName":"\u5f20\u5bb6\u56ed"},{"station":8,"stateName":"\u8881\u5bb6\u6751"},{"station":9,"stateName":"\u674e\u738b\u6865"},{"station":10,"stateName":"\u768b\u4ead\u575d"},{"station":11,"stateName":"\u5584\u8d24\u575d"},{"station":12,"stateName":"\u5584\u8d24\u793e\u533a"},{"station":13,"stateName":"\u6c88\u5858\u6e7e"},{"station":14,"stateName":"\u4e8c\u7eba\u673a\u603b\u5382"},{"station":15,"stateName":"\u957f\u4e50\u8def"},{"station":16,"stateName":"\u5927\u5173\u6865\u897f"},{"station":17,"stateName":"\u6559\u5de5\u8def\u5858\u6cb3\u8def\u53e3"},{"station":18,"stateName":"\u4fdd\u4ead\u5df7"},{"station":19,"stateName":"\u6d59\u6c5f\u5de5\u5546\u5927\u5b66"},{"station":20,"stateName":"\u82b1\u56ed\u65b0\u6751"},{"station":21,"stateName":"\u6559\u5de5\u8def\u82b1\u56ed\u4ead"},{"station":22,"stateName":"\u5e86\u4e30\u6751"},{"station":23,"stateName":"\u676d\u5927\u8def"},{"station":24,"stateName":"\u9ec4\u9f99\u6d1e"},{"station":25,"stateName":"\u9ec4\u9f99\u4f53\u80b2\u4e2d\u5fc3"}]}}

^C
jrhmpt01:/root# vim x3.pl 
jrhmpt01:/root# perl x3.pl 307 0
$str is %E6%9D%AD%E5%B7%9E
$content is {"code":1000,"msg":"success!","data":{"buses":[{"busId":0,"station":-1,"state":-1,"distance":-1,"reporTime":-1}],"stations":[{"station":1,"stateName":"\u5218\u6587\u6751"},{"station":2,"stateName":"\u8584\u677f\u5206\u5382"},{"station":3,"stateName":"\u6bdb\u7af9\u5c71"},{"station":4,"stateName":"\u6c88\u5bb6\u6865"},{"station":5,"stateName":"\u7126\u5316\u5206\u5382"},{"station":6,"stateName":"\u676d\u73bb"},{"station":7,"stateName":"\u5f20\u5bb6\u56ed"},{"station":8,"stateName":"\u8881\u5bb6\u6751"},{"station":9,"stateName":"\u674e\u738b\u6865"},{"station":10,"stateName":"\u768b\u4ead\u575d"},{"station":11,"stateName":"\u5584\u8d24\u575d"},{"station":12,"stateName":"\u5584\u8d24\u793e\u533a"},{"station":13,"stateName":"\u6c88\u5858\u6e7e"},{"station":14,"stateName":"\u4e8c\u7eba\u673a\u603b\u5382"},{"station":15,"stateName":"\u957f\u4e50\u8def"},{"station":16,"stateName":"\u5927\u5173\u6865\u897f"},{"station":17,"stateName":"\u6559\u5de5\u8def\u5858\u6cb3\u8def\u53e3"},{"station":18,"stateName":"\u4fdd\u4ead\u5df7"},{"station":19,"stateName":"\u6d59\u6c5f\u5de5\u5546\u5927\u5b66"},{"station":20,"stateName":"\u82b1\u56ed\u65b0\u6751"},{"station":21,"stateName":"\u6559\u5de5\u8def\u82b1\u56ed\u4ead"},{"station":22,"stateName":"\u5e86\u4e30\u6751"},{"station":23,"stateName":"\u676d\u5927\u8def"},{"station":24,"stateName":"\u9ec4\u9f99\u6d1e"},{"station":25,"stateName":"\u9ec4\u9f99\u4f53\u80b2\u4e2d\u5fc3"}]}}


字节 -> decode ->字符串 ->encode ->字节


decode_json 必须是unicode形式的字符


字符<-decode_json<-字节
字符->encode_json->字节

posted @ 2016-03-18 21:28  czcb  阅读(138)  评论(0编辑  收藏  举报