json-str.ts 372 Bytes
Newer Older
hucy's avatar
hucy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
export const jsonStr = function (json_data: any) {
  let cache = [] as any;
  const json_str = JSON.stringify(json_data, function (key, value) {
    if (typeof value === 'object' && value !== null) {
      if (cache.indexOf(value) !== -1) {
        return;
      }
      cache.push(value);
    }
    return value;
  });
  cache = null; //释放cache
  return json_str;
};