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":"u5218u6587u6751"},{"station":2,"stateName":"u8584u677fu5206u5382"},{"station":3,"stateName":"u6bdbu7af9u5c71"},{"station":4,"stateName":"u6c88u5bb6u6865"},{"station":5,"stateName":"u7126u5316u5206u5382"},{"station":6,"stateName":"u676du73bb"},{"station":7,"stateName":"u5f20u5bb6u56ed"},{"station":8,"stateName":"u8881u5bb6u6751"},{"station":9,"stateName":"u674eu738bu6865"},{"station":10,"stateName":"u768bu4eadu575d"},{"station":11,"stateName":"u5584u8d24u575d"},{"station":12,"stateName":"u5584u8d24u793eu533a"},{"station":13,"stateName":"u6c88u5858u6e7e"},{"station":14,"stateName":"u4e8cu7ebau673au603bu5382"},{"station":15,"stateName":"u957fu4e50u8def"},{"station":16,"stateName":"u5927u5173u6865u897f"},{"station":17,"stateName":"u6559u5de5u8defu5858u6cb3u8defu53e3"},{"station":18,"stateName":"u4fddu4eadu5df7"},{"station":19,"stateName":"u6d59u6c5fu5de5u5546u5927u5b66"},{"station":20,"stateName":"u82b1u56edu65b0u6751"},{"station":21,"stateName":"u6559u5de5u8defu82b1u56edu4ead"},{"station":22,"stateName":"u5e86u4e30u6751"},{"station":23,"stateName":"u676du5927u8def"},{"station":24,"stateName":"u9ec4u9f99u6d1e"},{"station":25,"stateName":"u9ec4u9f99u4f53u80b2u4e2du5fc3"}]}}

^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":"u5218u6587u6751"},{"station":2,"stateName":"u8584u677fu5206u5382"},{"station":3,"stateName":"u6bdbu7af9u5c71"},{"station":4,"stateName":"u6c88u5bb6u6865"},{"station":5,"stateName":"u7126u5316u5206u5382"},{"station":6,"stateName":"u676du73bb"},{"station":7,"stateName":"u5f20u5bb6u56ed"},{"station":8,"stateName":"u8881u5bb6u6751"},{"station":9,"stateName":"u674eu738bu6865"},{"station":10,"stateName":"u768bu4eadu575d"},{"station":11,"stateName":"u5584u8d24u575d"},{"station":12,"stateName":"u5584u8d24u793eu533a"},{"station":13,"stateName":"u6c88u5858u6e7e"},{"station":14,"stateName":"u4e8cu7ebau673au603bu5382"},{"station":15,"stateName":"u957fu4e50u8def"},{"station":16,"stateName":"u5927u5173u6865u897f"},{"station":17,"stateName":"u6559u5de5u8defu5858u6cb3u8defu53e3"},{"station":18,"stateName":"u4fddu4eadu5df7"},{"station":19,"stateName":"u6d59u6c5fu5de5u5546u5927u5b66"},{"station":20,"stateName":"u82b1u56edu65b0u6751"},{"station":21,"stateName":"u6559u5de5u8defu82b1u56edu4ead"},{"station":22,"stateName":"u5e86u4e30u6751"},{"station":23,"stateName":"u676du5927u8def"},{"station":24,"stateName":"u9ec4u9f99u6d1e"},{"station":25,"stateName":"u9ec4u9f99u4f53u80b2u4e2du5fc3"}]}}


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


decode_json 必须是unicode形式的字符


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

原文地址:https://www.cnblogs.com/hzcya1995/p/13350939.html