Skip to content

介绍 ​

工具库Json模块。

使用方法 ​

javascript
const UtilsJson = require('ee-core/utils/json');

API列表 ​

strictParse(str) ​

  • str [String] - 字符串

字符串转对象

readSync(filepath) ​

  • filepath [String] - 文件的绝对路径

同步读取一个json文件。

writeSync(filepath, str, options) ​

  • filepath [String] - json文件的绝对路径
  • str [String|Object] - 对象或字符串对象
  • options
    • space [Number] - 缩进,默认2

同步写入一个对象或对象字符串到文件。

read(filepath) ​

异步读取一个json文件。返还promise

write(filepath, str, options) ​

  • filepath [String] - json文件的绝对路径
  • str [String|Object] - 对象或字符串对象
  • options
    • space [Number] - 缩进,默认2

异步写入一个对象或对象字符串到文件。