AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

toJSON

介绍

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 字符串包含以下字段:

  • operator: 该 FuzzyCompositeTerm 对象的运算符。可能值为 "AND"、"OR" 和 "NOT"。
  • terms: 一个 FuzzyTerm 对象数组,表示参与运算的 FuzzyTerm 对象。FuzzyTerm 对象也可以是 FuzzyCompositeTerm 对象。

该方法将递归调用 FuzzyTerm 对象的 toJSON() 方法,得到完整的 JSON 字符串。

异常

无异常。

兼容性

该方法兼容所有支持 ES6 的现代浏览器。

参考链接