跳到主要内容

ToJSON

将 ApiHyperlink 对象转换为 JSON 对象。

语法

expression.ToJSON(bWriteStyles);

expression - 表示 ApiHyperlink 类的变量。

参数

名称必需/可选数据类型默认值描述
bWriteStyles必需boolean指定使用的样式是否将写入 JSON 对象。

返回值

JSON

示例

此示例将 ApiHyperlink 对象转换为 JSON 对象。

// How to get a JSON from the hyperlink.

// Convert the hyperlink to json and add it to the paragraph.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
let hyperlink = Api.CreateHyperlink("https://api.onlyoffice.com/", "ONLYOFFICE Document Builder", "ONLYOFFICE for developers");
let json = hyperlink.ToJSON(true);
let hyperlinkFromJSON = Api.FromJSON(json);
hyperlinkFromJSON.SetDefaultStyle();
paragraph.AddElement(hyperlinkFromJSON);