我有一个生成JSON的Web服务。我们对它进行jQuery REST调用并将数据绑定到Tables。
该服务是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
答案 0 :(得分:0)
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"`
如果网站返回空字符串,则会失败。
答案 1 :(得分:0)
您的服务器上可能已损坏,因为您的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")))