Json Power Bi查询到web服务-错误:表达式。错误:无法将值转换为类型记录

Json Power Bi查询到web服务-错误:表达式。错误:无法将值转换为类型记录,json,rest,powerbi,powerquery,Json,Rest,Powerbi,Powerquery,我有一个生成JSON的web服务。我们对它进行jqueryrest调用,并将数据绑定到表中 该服务是C#WEBAPI,代码如下: data = serializer.Serialize(rows); return Request.CreateResponse(HttpStatusCode.OK, lstFilteredData, Configuration.Formatters.JsonFormatter); "[{\"School\":\"UM \",\"Students\":\"5

我有一个生成JSON的web服务。我们对它进行jqueryrest调用,并将数据绑定到表中

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

  data = serializer.Serialize(rows);
  return Request.CreateResponse(HttpStatusCode.OK, lstFilteredData, Configuration.Formatters.JsonFormatter);
"[{\"School\":\"UM \",\"Students\":\"500\"},{\"School\":\"FIU \",\"Students\":\"700\"},{\"School\":\"UF \",\"Students\":\"600\"},{\"School\":\"GT \",\"Students\":\"300\"}]"
 $.ajax({
        url: 'https://myservices')),
        type: 'GET',
        dataType: 'json',
        cache: false,
        crossDomain: true,
        //async: false,
        success: function (data){  onQuerySucceededWeb(data,true,param);}
    }); 
它生成的JSON如下所示:

  data = serializer.Serialize(rows);
  return Request.CreateResponse(HttpStatusCode.OK, lstFilteredData, Configuration.Formatters.JsonFormatter);
"[{\"School\":\"UM \",\"Students\":\"500\"},{\"School\":\"FIU \",\"Students\":\"700\"},{\"School\":\"UF \",\"Students\":\"600\"},{\"School\":\"GT \",\"Students\":\"300\"}]"
 $.ajax({
        url: 'https://myservices')),
        type: 'GET',
        dataType: 'json',
        cache: false,
        crossDomain: true,
        //async: false,
        success: function (data){  onQuerySucceededWeb(data,true,param);}
    }); 
我们有jQuery REST,它成功地使用了如下服务:

  data = serializer.Serialize(rows);
  return Request.CreateResponse(HttpStatusCode.OK, lstFilteredData, Configuration.Formatters.JsonFormatter);
"[{\"School\":\"UM \",\"Students\":\"500\"},{\"School\":\"FIU \",\"Students\":\"700\"},{\"School\":\"UF \",\"Students\":\"600\"},{\"School\":\"GT \",\"Students\":\"300\"}]"
 $.ajax({
        url: 'https://myservices')),
        type: 'GET',
        dataType: 'json',
        cache: false,
        crossDomain: true,
        //async: false,
        success: function (data){  onQuerySucceededWeb(data,true,param);}
    }); 
我正在尝试使用Power Bi报告这些数据。我的PowerBi查询脚本是: 让

我得到了这个错误:

**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")))

如果您使用=Text.FromBinary(Web.Contents(“)),会显示什么?我应该把它放在哪里?代替我的整个查询脚本?相同的.Expression.Error:我们无法将值“[{\”School\”:\“UM…”转换为键入Record。如果您将
Record.ToTable(Source)
替换为
Table.FromList(Source,Splitter.SplitByNothing(),该怎么办,null,null,ExtraValues.Error)
,然后用
Table.ExpandRecordColumn(#“转换为Table”,“Column1”,“School”,“Students”},{“School”,“Students”})替换接下来的两个步骤。
表达式。错误:我们无法将值“[{\“School\:\:\”UM…”转换为类型列表。详细信息:此行:=Table.ExpandRecordColumn(#”转换为表“,”Column1“,“{”School“,”Students“},{”School“,”Students“}”)时产生以下错误:表达式。错误:我们无法将二进制类型的值转换为文本类型。详细信息:value=Binary-type=type查看浏览器中服务返回的实际屏幕截图。错误实际上在这一行:=Text.Range(Source,1,Text.Length(Source)-2)噢,用
Source=Text.FromBinary(Web.Contents)替换第一步https://mywebservices”),
。这应该将web请求转换为文本,然后可以将JSON字符串转换为JSON数组,该数组可以通过JSON.Document.=JSON.Document(Custom1)转换为列表DataFormat.Error:我们在JSON输入的末尾发现了额外的字符。详细信息:Value=\Position=2是的,原来我们在服务中使用了双重编码。