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);