转换:
var str = encodeURIComponent(JSON.stringify(data))
解析:
var obj = JSON.parse(decodeURIComponent(str));
本文介绍了一种使用JavaScript进行数据转换和解析的有效方法。通过使用encodeURIComponent和decodeURIComponent结合JSON.stringify及JSON.parse,可以轻松地将复杂的数据结构转换为字符串,并在需要时将其还原回原始数据格式。
转换:
var str = encodeURIComponent(JSON.stringify(data))
解析:
var obj = JSON.parse(decodeURIComponent(str));
5442