JSON中的未知DOM表示

时间:2016-07-03 03:19:40

标签: json api text slack-api

我有一个看起来像这样的Slack帖子:

What the file looks like rendered

我使用files.list方法查询Slack API,并使用文件对象的url_private属性检索此文件:

{
"version":100,
"revision":206,
"root":{
    "children":[
        {
            "type":"h2",
            "text":"Header 2"
        },
        {
            "type":"p",
            "text":""
        },
        {
            "type":"p",
            "text":"\"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\""
        },
        {
            "type":"p",
            "text":""
        },
        {
            "type":"p",
            "text":"Bold. Italics. Code.",
            "formats":{
                "b":[
                    0,
                    5
                ],
                "i":[
                    6,
                    20
                ],
                "code":[
                    15,
                    19
                ]
            }
        },
        {
            "type":"p",
            "text":""
        },
        {
            "type":"ol",
            "text":"Point one"
        },
        {
            "type":"ol",
            "text":"Point two"
        },
        {
            "type":"ol",
            "text":"Point three"
        },
        {
            "type":"p",
            "text":""
        },
        {
            "type":"p",
            "text":""
        }
    ]
}

}

现在我的问题是:这是格式化文本的常见JSON表示,还是Slack自己编写的东西?如果它很常见,它叫什么?

编辑:我知道这是一个JavaScript对象,我知道这是一个JSON响应。我的困惑与它如何处理文本格式有关。我想知道这是否是表示富文本格式的标准形式。

1 个答案:

答案 0 :(得分:0)

它被称为JavaScript对象。

在JavaScript中,您可以访问其属性:

obj.root.children[index].type;
obj.root.children[index].text;

示例:

obj.root.children[0].type; // ouputs : "h2"

很明显,Slack将他们的帖子表示为你可以按照你想要的方式使用的东西,否则为什么要通过API提供呢?