[英]Powerautomate Parsing JSON Array
我在這里看到了 JSON 數組問題,但我還是有點迷茫,所以需要一些額外的幫助。
這是設置:My Flow 在我的數據庫上調用存儲過程,該存儲過程返回此 JSON:
{
"ResultSets": {
"Table1": [
{
"OrderID": 9518338,
"BasketID": 9518338,
"RefID": 65178176,
"SiteConfigID": 237
}
]
},
"OutputParameters": {}
}
然后我使用 PARSE JSON 操作來獲得看起來相同的結果,但現在我被告知它已被解析並且我可以調用變量。
問題是,當我嘗試僅調用 SiteConfigID 時,我得到“您選擇的 output 在集合中,需要循環訪問才能訪問。此操作不能在 foreach 中。”
經過一些研究,我知道這里發生了什么。 Table1 是一個數組,我需要告訴 PowerAutomate 只獲取該數組的第一條記錄,以便它知道它只處理一條記錄而不是整個數組。 很公平。 所以我啟動了一個“將值返回給 Virtual Power Agents”的操作,只是為了查看我的 output。我知道我應該在這里使用“first”表達式或“get [0] from array expression”,但我不能似乎讓他們工作。 以下是我嘗試過的方法和我得到的錯誤:
試過:
first(body('Parse-Sproc')?['Table1/SiteConfigID'])
Got: InvalidTemplate. Unable to process template language expressions in action 'Return_value(s)_to_Power_Virtual_Agents' inputs at line '0' and column '0': 'The template language function 'first' expects its parameter be an array or a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#first for usage details.'.
還嘗試過:
body('Parse-Sproc')?['Table1/SiteconfigID']
which just returns a null valued variable
最后我試過了
outputs('Parse-Sproc')?['Table1']?['value'][0]?['SiteConfigID']
Which STILL gives me a null-valued variable. It's the worst.
In that last expression, I also switched the variable type in the return to pva action to a string instead of a number, no dice.
Also, changed 'outputs' in that expression for 'body' .. also no dice
需要明確的是:我正在尋找的最終結果是系統僅將“SiteConfigID”作為字符串或整數返回,以便我可以將 pipe 轉換為虛擬代理。
我相信這就是您需要的表達...
body('Parse-Sproc')?['ResultSets']['Table1'][0]?['SiteConfigID']
你可以看到我只是向下遍歷到 object 並通過數組來獲取值。
當然,我沒有你的確切流程,但如果我使用你的 JSON 並將其加載到Parse JSON
步驟以獲取架構,我就能得到結果。 不過,我確實得到了一個不同的模式,所以看看它是否直接翻譯會很有趣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.