我有一个JSON输出,如下所示。我使用getjson来获取数据。我的目标是将datetime
和value
字段(斜体和粗体)视为[16:35:08,30.579 kbit/s],[16:35:38,23.345 kbit/s]
。有没有办法成功呢?谢谢,
{
"prtg-version": "17.3.33.2830",
"treesize": 4,
"histdata": [{
"***datetime***": "04.12.2017 16:35:08",
"datetime_raw": 43073.5660648727,
"value": "111.983 KByte",
"value_raw": 114670936.0000,
"***value***": "30.579 kbit/s",
"value_raw": 3822364.5333,
"value": "107.893 KByte",
"value_raw": 110482503.0000,
"value": "29.462 kbit/s",
"value_raw": 3682750.1000,
"value": "4.090 KByte",
"value_raw": 4188433.0000,
"value": "1.117 kbit/s",
"value_raw": 139614.4333,
"coverage": "100 %",
"coverage_raw": 10000
}, {
"***datetime***": "04.12.2017 16:35:38",
"datetime_raw": 43073.5664120718,
"value": "85.464 KByte",
"value_raw": 87514907.0000,
"***value***": "23.345 kbit/s",
"value_raw": 2918136.2788,
"value": "81.993 KByte",
"value_raw": 83960378.0000,
"value": "22.397 kbit/s",
"value_raw": 2799612.4708,
"value": "3.471 KByte",
"value_raw": 3554529.0000,
"value": "948 kbit/s",
"value_raw": 118523.8079,
"coverage": "100 %",
"coverage_raw": 10000
}]
}
答案 0 :(得分:0)
只需将数组映射到函数中,然后根据需要解析值。
以下示例使用:
public static string GetBusDate(bool mtdIndicator, bool prev2BusDtInd)
{
string busDate = Helper.PreviousBusinessDate;
if (mtdIndicator)
{
busDate = Helper.FOMBusDt;
}
else if (prev2BusDtInd)
{
busDate = Helper.Previous2BusinessDate;
}
return busDate;
}
输出值相关方法:
``
检查代码段:
const result = data.histdata.map(hist => {
const datetime = hist['***datetime***'].split(' ')[1];
const value = hist['***value***'];
return `${datetime},${value}`;
});