toJSON()
方法是 FuzzyCompositeTerm 类中的一个方法,用于将 FuzzyCompositeTerm 对象转换成 JSON 格式的字符串,以方便在应用程序中进行传输和存储。
term.toJSON()
无参数。
一个表示 FuzzyCompositeTerm 对象的 JSON 字符串。
const term1 = new FuzzyCompositeTerm("AND", [new FuzzyTerm("good"), new FuzzyTerm("bad")]);
const term2Json = term1.toJSON();
console.log(term2Json); // {"operator":"AND","terms":[{"type":"FuzzyTerm","value":"good"},{"type":"FuzzyTerm","value":"bad"}]}
toJSON()
方法将 FuzzyCompositeTerm 对象转换成 JSON 格式的字符串。返回的 JSON 字符串包含以下字段:
该方法将递归调用 FuzzyTerm 对象的 toJSON()
方法,得到完整的 JSON 字符串。
无异常。
该方法兼容所有支持 ES6 的现代浏览器。