JSON.stringify
编码JSON字符串,是ECMAScript标准内建对象JSON的方法。JavaScript、Rust策略可用;Python策略使用标准库json。
JSON.stringify(obj)示例
编码一个对象,输出编码后的JSON字符串。
javascript
function main() {
let s1 = {"num": "8754613216564987646512354656874651651358"}
Log("JSON.stringify:", JSON.stringify(s1))
// 输出:JSON.stringify: {"num":"8754613216564987646512354656874651651358"}
// JSON.stringify(s1) 返回字符串
}
rust
fn main() {
// Rust 没有 JSON.stringify,JsonValue 的 to_string() 输出紧凑JSON(对象的键按字母序)
let mut m = std::collections::BTreeMap::new();
m.insert("num".to_string(),
JsonValue::String("8754613216564987646512354656874651651358".to_string()));
let s1 = JsonValue::Object(m);
Log!("JSON.stringify:", s1.to_string());
// 输出:JSON.stringify: {"num":"8754613216564987646512354656874651651358"}
}返回值
| 类型 | 描述 |
string | 返回值为编码后的 |
参数
| 名称 | 类型 | 必填 | 描述 |
obj | string / number / bool / object / array / function / any | 是 | 该参数为需要编码的对象。 |
参考
备注
仅支持JavaScript语言。