Power Bi Query to web service - Error: Expression.Error: We cannot convert the value to type Record

Power Bi Query to web service - Error: Expression.Error: We cannot convert the value to type Record

我有一个生成 JSON 的 Web 服务。我们对其进行 jQuery REST 调用并将数据绑定到表。

该服务是 C# WEBAPI,代码如下:

  data = serializer.Serialize(rows);
  return Request.CreateResponse(HttpStatusCode.OK, lstFilteredData, Configuration.Formatters.JsonFormatter);

它产生的 JSON 是这样的:

"[{\"School\":\"UM \",\"Students\":\"500\"},{\"School\":\"FIU \",\"Students\":\"700\"},{\"School\":\"UF \",\"Students\":\"600\"},{\"School\":\"GT \",\"Students\":\"300\"}]"

我们有 jQuery REST 成功使用了这样的服务:

 $.ajax({
        url: 'https://myservices')),
        type: 'GET',
        dataType: 'json',
        cache: false,
        crossDomain: true,
        //async: false,
        success: function (data){  onQuerySucceededWeb(data,true,param);}
    }); 

我正尝试使用 Power Bi 报告该数据。我的 PowerBi 查询脚本是: 让

Source = Json.Document(Web.Contents("https://mywebservices")),
  #"Converted to Table" = Record.ToTable(Source),
    #"Expanded Value" = Table.ExpandListColumn(#"Converted to Table", "Value"),
    #"Expanded Value1" = Table.ExpandRecordColumn(#"Expanded Value", "Value", {"School", "Students"}, {"Value.School", "Value.Students"})

in 
  #"Expanded Value1"

我收到这个错误:

**Expression.Error: We cannot convert the value "[{"School":"UM      ..." to type Record.**
Details:
    Value=[{"School":"UM        ","Students":"500"},{"School":"FIU       ","Students":"700"},{"School":"UF        ","Students":"600"},{"School":"GT        ","Students":"300"}]
    Type=Type

Json.Document 正在返回一个文本值,因为返回的 JSON 是一个字符串。如果删除引号,Json.Document 应该将其解析为对象列表。这应该有效:

let
    Source = Web.Contents("https://mywebservices")
    Custom1 = Text.Range(Source, 1, Text.Length(Source) - 2),
    Custom2 = Json.Document(Custom1),
    #"Converted to Table" = Table.FromList(Custom2, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"School", "Students"}, {"School", "Students"})
in
    #"Expanded Column1"`

如果网站返回空字符串,这将失败。

您的服务器可能出现问题,因为您的 JSON 是对象的 JSON 字符串。如果服务器没有对 JSON 文本进行字符串化,即按字面意思生成这些字节,则您的 M 查询会起作用:

[{"School":"UM ","Students":"500"},{"School":"FIU ","Students":"700"},{"School":"UF ","Students":"600"},{"School":"GT ","Students":"300"}]

如果你只是想让你的 M 再次工作,你可以对JSON进行双重解码:

= Json.Document(Json.Document(Web.Contents("https://mywebservices")))