我有一个从JSON文档中提取节点的函数,如下所示:
...
Json = GetJson(Url),
Value = Json[#"values"]
值对应于JSON文档中的实际节点。
我想概括这段代码,并提供节点的名称作为变量,如:let myFunc = (parentNodeName as text) =>
...
Json = GetJson(Url),
Value = Json[parentNodeName]
但是得到这个错误:An error occurred in the ‘myFunc’ query. Expression.Error: The field 'parentNodeName' of the record wasn't found.
如何动态引用JSON节点?
Try
(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