动态地指power查询中的JSON节点

发布于 2025-01-25 04:44:55 字数 397 浏览 2 评论 0原文

我的功能可以从JSON文档中提取节点,如下所示:

...
Json  = GetJson(Url),
Value = Json[#"values"]

值对应于JSON文档中的实际节点。

我想概括此代码,并提供节点的名称为一个变量:

let myFunc = (parentNodeName as text) =>
...
Json  = GetJson(Url),
Value = Json[parentNodeName]

但是获取此错误: “ MyFunc”查询中发生了错误。 Expression.Error:未找到记录的字段'parentNodeName。

如何动态地参考JSON节点?

I have a function that extracts a node from JSON document as follows:

...
Json  = GetJson(Url),
Value = Json[#"values"]

values correspond to the actual node within the JSON document.

I would like to generalize this piece of code and provide the name of the node as a variable like:

let myFunc = (parentNodeName as text) =>
...
Json  = GetJson(Url),
Value = Json[parentNodeName]

However getting this error:
An error occurred in the ‘myFunc’ query. Expression.Error: The field 'parentNodeName' of the record wasn't found.

How can I refer to the JSON node dynamically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

茶花眉 2025-02-01 04:44:55

尝试

(Json, parentNodeName ) =>
let
...
Value = Record.Field(Json,parentNodeName)
in Value

示例代码:

let Json = Json.Document(Web.Contents("http://soundcloud.com/oembed?url=http%3A//soundcloud.com/forss/flickermood&format=json")),
Value=myFunc(Json,"title")
in Value

和myfunc:

(Json, parentNodeName ) =>
let 
Value = Record.Field(Json,parentNodeName)
in Value

Try

(Json, parentNodeName ) =>
let
...
Value = Record.Field(Json,parentNodeName)
in Value

sample code:

let Json = Json.Document(Web.Contents("http://soundcloud.com/oembed?url=http%3A//soundcloud.com/forss/flickermood&format=json")),
Value=myFunc(Json,"title")
in Value

and myFunc:

(Json, parentNodeName ) =>
let 
Value = Record.Field(Json,parentNodeName)
in Value
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文