-
Notifications
You must be signed in to change notification settings - Fork 0
API JSON
Liu.Yandong.Hanks edited this page Aug 26, 2026
·
4 revisions
JSON 解析与序列化 API。
JSON 在 AuroraScript 值与 JSON 文本之间转换。它是静态对象,没有构造函数。
支持普通对象、通用数组、紧凑数组、HashMap 以及可序列化的原始值。
Tip
JSON 面向标准互操作,可能将运行时类型简化为普通对象、数组或字符串。若需保留 AuroraScript 类型身份,请使用 TDoc。
参数
| 名称 | Type | 必填 | 说明 |
|---|---|---|---|
text |
string |
是 | 有效的 JSON 文本。 |
返回值
any — 对应的 AuroraScript 值。
行为
格式错误的输入会触发运行时错误。
示例
var config = JSON.parse('{"name":"Aurora","enabled":true}');
return config.name; // "Aurora"参数
| 名称 | Type | 必填 | 说明 |
|---|---|---|---|
value |
any |
是 | 要序列化的值。 |
indented |
boolean |
否 |
true 时输出缩进格式。 |
返回值
string — JSON 文本。
Warning
循环引用无法序列化,会触发运行时错误。序列化前请打破循环。
示例
var text = JSON.stringify({ name: "Aurora", values: [1, 2] }, true);
return text.contains("\n"); // trueAuroraScript.JIT 4.0.0 · 文档首页 · 仓库 · MIT License