[英]Select the first element in a JSON array in Microsoft stream analytics query
所以我遇到了一些問題。 我從外部API檢索一些weatherdata。 這將作為JSON返回並發送到Azure IoT中心。 流分析將json處理成適當的格式,但我在這里遇到了問題。
元素:Current_Condition是一種數組格式。 它總是在[0]位置有一個元素。 我只需要從第一個位置獲取該數組的數據,而不需要像id那樣的過濾器。
這里是完整的數據
{
"deviceId": "aNewDevice",
"data": {
"data": {
"current_condition": [
{
"cloudcover": "0",
"FeelsLikeC": "0",
"FeelsLikeF": "32",
"humidity": "100",
"observation_time": "10:00 AM",
"precipMM": "0.0",
"pressure": "1020",
"temp_C": "2",
"temp_F": "36",
"visibility": "0",
"weatherCode": "143",
"weatherDesc": [ { "value": "Fog, Mist" } ],
"weatherIconUrl": [ { "value": "http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0006_mist.png" } ],
"winddir16Point": "SSW",
"winddirDegree": "210",
"windspeedKmph": "7",
"windspeedMiles": "4"
}
],
"request": [
{
"query": "Nijmegen, Netherlands",
"type": "City"
}
]
}
}
}
還有一些關於我究竟需要做什么的解釋(不只是一個例子或代碼答案)將來會很好。 (請求元素畢竟有同樣的問題。)
提前致謝 :)
您需要使用GetArrayElement函數。 例如:
SELECT GetRecordProperty(GetArrayElement(Current_Condition, 0), 'humidity')
為了使它更好一點,你可以將查詢分成兩個步驟:
WITH CurrentConditions AS
(
SELECT deviceId, GetArrayElement(Current_Condition, 0) as conditions
FROM input
)
SELECT deviceID, conditions.humidity
FROM CurrentConditions
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.