如果要將編輯過的json中文字串,只要將\取代成%,再使用javascript的unescape function就可以解碼。
var encodejson = "\u8521\u5927\u75E3"; encodejson = encodejson.replace("\\","%"); document.write("json decode :" + unescape(encodejson) + " "); var test = "蔡大痣"; document.write("test:" + test + " "); document.write("to edcode from test:" + escape(test) + " "); document.write("to decode from test:" + unescape(test) + " ");
輸出:
json decode :蔡大痣
test:蔡大痣
to edcode from test:%u8521%u5927%u75E3
to decode from test:蔡大痣
沒有留言:
張貼留言
留個話吧:)