js中序列化和反序列化对象的方法是什么?
网友回复
var a = { "title": 'good', "name": "ddd", "age": 16 }; //序列化对象 consol...
点击查看剩余70%
<script> function serialize(obj, name) { var result = ""; function serializeInternal(o, path) { for (p in o) { var value = o[p]; if (typeof value != "object") { if (typeof value == "string") { result += "\n" + path + "[" + (isNaN(p)?"\""+p+"\"": p) + "] = " + "\"" + value.replace(/\"/g, "\\\"") + "\""+";"; } else { result += "\n" + path + "[" + (isNaN(p)?"\""+p+"\"": p) + "] = " + value+";"; } } else { if (value instanceof Array) { result += "\n" + path +"[" + (isNaN(p)?"\""+p+"\"": p) + "]"+"="+"new Array();"; serializeInternal(value, path + "[" + (isNaN(p)?"\""+p...
点击查看剩余70%