我是使用 ION 的新手,所以请原谅这个可能很简单的问题。在查看文档中提供的食谱样本之一...
let ion = require('ion-js');
let unformatted = '{level1: {level2: {level3: "foo"}, x: 2}, y: [a,b,c]}';
let reader = ion.makeReader(unformatted);
let writer = ion.makePrettyWriter();
writer.writeValues(reader);
writer.close();
console.log(String.fromCharCode.apply(null, writer.getBytes()));
ION 可以接收 JSON 对象而不是字符串吗?执行类似下面的操作,我将未格式化的变量从字符串更改为 JSON 对象,导致写入器的字节为零......
let ion = require('ion-js');
let unformatted = {level1: {level2: {level3: "foo"}, x: 2}, y: [a,b,c]};
let reader = ion.makeReader(unformatted);
let writer = ion.makePrettyWriter();
writer.writeValues(reader);
writer.close();
console.log(String.fromCharCode.apply(null, writer.getBytes()));