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是Yuka js库中的FuzzySet对象的一个方法,用于将FuzzySet对象序列化为JSON格式。

示例

const fs = new FuzzySet(['apple', 'banana', 'cherry']);
const json = fs.toJSON();
console.log(json);
// {"keyMap":{"a":[[0,"apple"]],"b":[[1,"banana"]],"c":[[2,"cherry"]]},"items":["apple","banana","cherry"],"useLevenshtein":true,"threshold":0.6}

返回值

toJSON方法返回一个FuzzySet对象的JSON格式的字符串。

参数

toJSON方法不接受任何参数。

示例说明

此示例创建了一个名为fs的FuzzySet对象,其中包含三个字符串。然后将该对象序列化为JSON格式并存储在json变量中。最后将该变量打印到控制台上,结果如下:

{
  "keyMap": {
    "a": [
      [0, "apple"]
    ],
    "b": [
      [1, "banana"]
    ],
    "c": [
      [2, "cherry"]
    ]
  },
  "items": [
    "apple",
    "banana",
    "cherry"
  ],
  "useLevenshtein": true,
  "threshold": 0.6
}

该JSON对象包含一个keyMap属性,其中包含每个字符串及其索引的映射,一个items属性,其中包含所有字符串的数组,一个useLevenshtein属性,用于指定是否使用Levenshtein算法计算相似性,以及一个threshold属性,用于指定相似性阈值。