如何将 JSON 条记录插入 PowerApps 中的公共数据服务实体?

How to insert JSON records into a Common Data Service Entity in PowerApps?

我需要将数据条目插入到 PowerApps 中的通用数据服务 (CDS) 实体中。 这是我的实体的样子:

现在,如果我尝试通过导入 excel table 来插入条目,如下所示,power 查询会将其正确解释为自己的 table。

步骤 => 'Get Data' > 'Excel' > 'Browse' (onedrive)

但是如果我尝试通过 JSON 文件做同样的事情,那么它无法将其分解为属性。

样本JSON:

[
  {
    "patientID": "p1",
    "phoneNumber": 9876543210,
    "patientName": "Abc",
    "DOB": "17/06/2006",
    "Address": "Hyderabad"
  },
  {
    "patientID": "p2",
    "phoneNumber": 9976543210,
    "patientName": "def",
    "DOB": "17/06/2006",
    "Address": "Hyderabad"
  },
  {
    "patientID": "p3",
    "phoneNumber": 9996543210,
    "patientName": "ghi",
    "DOB": "17/06/2006",
    "Address": "Hyderabad"
  }
]

步骤 => 'Get Data' > 'JSON' > 'Browse' (onedrive)

PowerQuery对应解读:

然后如果我们进入第一条记录:

现在这应该被解释为 5 列 table,而不是 2 列 table,其中 'Key' 和 'Value' 作为 2 列。

一个可能的解决方案是: 'Convert to Table' > 'Transform Table- Transpose' > 'Transform Table- Use first row as headers'

结果如下:

但还是只有1条记录,本来应该是3条记录的

如何将 JSON 文件转换成 table 的方式与 Excel table 的处理方式相同? JSON 应该用不同的方式写吗?

获得记录列表后,将表达式传递给 Table.FromRecords 函数。它会给你预期的输出。

举个例子:

let
    serialised = "[{""patientID"": ""p1"",""phoneNumber"": 9876543210,""patientName"": ""Abc"",""DOB"": ""17/06/2006"",""Address"": ""Hyderabad""},{""patientID"": ""p2"",""phoneNumber"": 9976543210,""patientName"": ""def"",""DOB"": ""17/06/2006"",""Address"": ""Hyderabad""},{""patientID"": ""p3"",""phoneNumber"": 9996543210,""patientName"": ""ghi"",""DOB"": ""17/06/2006"",""Address"": ""Hyderabad""}]",
    json = Json.Document(serialised),
    toTable = Table.FromRecords(json)
in
    toTable

这给了我: