[英]Power Bi Query to web service - Error: Expression.Error: We cannot convert the value to type Record
I have a web service that produces JSON. 我有一个生成JSON的Web服务。 We make jQuery REST calls to it and bind the data to Tables. 我们对其进行jQuery REST调用,并将数据绑定到表。
The service is C# WEBAPI with code like this: 该服务是C#WEBAPI,其代码如下:
data = serializer.Serialize(rows);
return Request.CreateResponse(HttpStatusCode.OK, lstFilteredData, Configuration.Formatters.JsonFormatter);
It produces JSON that like this: 它产生如下的JSON:
"[{\"School\":\"UM \",\"Students\":\"500\"},{\"School\":\"FIU \",\"Students\":\"700\"},{\"School\":\"UF \",\"Students\":\"600\"},{\"School\":\"GT \",\"Students\":\"300\"}]"
We have jQuery REST that successfully consumes the service like this: 我们拥有jQuery REST,可以成功使用以下服务:
$.ajax({
url: 'https://myservices')),
type: 'GET',
dataType: 'json',
cache: false,
crossDomain: true,
//async: false,
success: function (data){ onQuerySucceededWeb(data,true,param);}
});
I'm tring to report on that data using Power Bi. 我打算使用Power Bi报告这些数据。 My PowerBi Query script is: let 我的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"
I'm getting this Error: 我收到此错误消息:
**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 is returning a text value because the JSON being returned is a string. Json.Document返回一个文本值,因为返回的JSON是一个字符串。 If you remove the quotes, Json.Document should parse it as a list of objects. 如果删除引号,则Json.Document应该将其解析为对象列表。 This should work: 这应该工作:
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"`
This would fail if the web site ever returned an empty string. 如果该网站返回空字符串,则将失败。
Something might have broken on your server, because your JSON is a JSON string of an object. 您的服务器上可能发生了某些故障,因为JSON是对象的JSON字符串。 Your M query would have worked if the server hadn't stringified the JSON text, ie produced literally these bytes: 如果服务器未对JSON文本进行字符串化(即按字面意义生成这些字节),则M查询将正常工作:
[{"School":"UM ","Students":"500"},{"School":"FIU ","Students":"700"},{"School":"UF ","Students":"600"},{"School":"GT ","Students":"300"}]
If you just want to get your M to work again, you can double-decode the JSON: 如果您只是想让M重新工作,可以对JSON进行双解码:
= Json.Document(Json.Document(Web.Contents("https://mywebservices")))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.