Json.Document

語法

Json.Document(jsonText as any, optional encoding as nullable number) as any

關於

傳回 JSON 文件的內容。

  • jsonText:JSON 檔的內容。 此參數的值可以是文字,也可以是由函數回傳的二進位值,例如 File.Contents
  • encoding TextEncoding.Type:,指定 JSON 檔中所使用的編碼方式。 若省略 encoding,則會使用 UTF8。

範例 1

傳回指定 JSON 文字的內容做為記錄。

使用方式

let
    Source = "{
        ""project"": ""Contosoware"",
        ""description"": ""A comprehensive initiative aimed at enhancing digital presence."",
        ""components"": [
            ""Website Development"",
            ""CRM Implementation"",
            ""Mobile Application""
        ]
    }",
    jsonDocument = Json.Document(Source)
in
    jsonDocument

輸出

[
    project = "Contosoware",
    description = "A comprehensive initiative aimed at enhancing digital presence."
    components =
    {
        "Website Development",
        "CRM Implementation",
        "Mobile Application"
    }
]

範例 2

傳回本機 JSON 檔案的內容。

使用方式

let
    Source = Json.Document(
        File.Contents("C:\test-examples\JSON\Contosoware.json")
    )
in
    Source

輸出

A record, list, or primitive value representing the JSON data contained in the file

範例 3

傳回在線 UTF16 編碼 JSON 檔案的內容。

使用方式

let
    Source = Json.Document(
        Web.Contents("htts://contoso.com/products/Contosoware.json"),
        TextEncoding.Utf16)
    )
in
    Source

輸出

A record, list, or primitive value representing the JSON UTF16 data contained in the file