Skip to content

API JSON

Liu.Yandong.Hanks edited this page Aug 19, 2026 · 3 revisions

JSON

JSON 解析与序列化

JSON parsing and serialization

脚本 API 目录

Script API Directory

概述

Overview

JSON 用于在 AuroraScript 值与 JSON 文本之间转换。支持普通对象、一般数组、Packed Array、HashMap 与可序列化的基础值;循环引用不能序列化。

JSON converts between AuroraScript values and JSON text. It supports ordinary objects, general arrays, packed arrays, HashMap, and serializable primitive values; circular references cannot be serialized.

JSON.parse(text)

Parameters:

  • text
    有效的 JSON 字符串。

    Valid JSON string.

Returns

对应的 AuroraScript 值。

The corresponding AuroraScript value.

边界行为

格式错误的文本会产生运行时错误。

Malformed input raises a runtime error.

var config = JSON.parse('{"name":"Aurora","enabled":true}');
return config.name;

JSON.stringify(value, [indented])

Parameters:

  • value
    待序列化值。

    Value to serialize.

  • indented
    可选布尔值,true 时输出缩进文本。

    Optional Boolean; true produces indented output.

Returns

JSON 字符串。

JSON string.

边界行为

遇到循环引用会抛出运行时错误。

A circular reference raises a runtime error.

var text = JSON.stringify({ name: "Aurora", values: [1, 2] }, true);
return text.contains("\n"); // true

Clone this wiki locally