JSON object cloning (JSON Object serialization) (function supported) and json serialization
During work, JSON objects need to be serialized and saved to SessionStorage. Therefore, you have written three methods: Cloning JSON objects and serializing and saving and reading JSON objects.
Var JSON_SERIALIZE_FIX = {PREFIX: "[[JSON_FUN_PREFIX _", SUFFIX: "_ JSON_FUN_SUFFIX]"}; /*** obtain JSON object data from sessionStorage based on the Key * @ param key the primary key saved * @ param type key added value (optional) */function getSessionJSONItem (Key, type) {if (type) {key = key + "_" + type;} return JSON. parse (sessionStorage. getItem (key), function (key, value) {if (typeof value = 'string' & value. indexOf (JSON_SERIALIZE_FIX.SUFFIX)> 0 & value. indexOf (JSON_SERIALIZE_FIX.PREFIX) = 0) {return eval ("(" + value. replace (JSON_SERIALIZE_FIX.PREFIX ,""). replace (JSON_SERIALIZE_FIX.SUFFIX, "") + ")");} return value ;}| {};} /*** save JSON object data to sessionStorage */function setSessionJSONItem (key, obj, type) {if (type) {key = key + "_" + type ;} sessionStorage. setItem (key, JSON. stringify (obj, function (key, value) {if (typeof value = 'function') {return JSON_SERIALIZE_FIX.PREFIX + value. toString () + JSON_SERIALIZE_FIX.SUFFIX;} return value;});}/*** clone a JSON object (function supported) * @ param obj json object */function cloneJSON (obj) {var sobj = JSON. stringify (obj, function (key, value) {if (typeof value = 'function') {return JSON_SERIALIZE_FIX.PREFIX + value. toString () + JSON_SERIALIZE_FIX.SUFFIX;} return value;}); return JSON. parse (sobj, function (key, value) {if (typeof value = 'string' & value. indexOf (JSON_SERIALIZE_FIX.SUFFIX)> 0 & value. indexOf (JSON_SERIALIZE_FIX.PREFIX) = 0) {return eval ("(" + value. replace (JSON_SERIALIZE_FIX.PREFIX ,""). replace (JSON_SERIALIZE_FIX.SUFFIX, "") + ")");} return value ;}| {};}