Answer the question
In order to leave comments, you need to log in
How to add a new series to JSON correctly?
Hello.
There is a JSON like
{
"FailedCount":[{"FailedCount_MEAS_VALUE":1,"DATETIME_CURRENT":"12:01"},
{"FailedCount_MEAS_VALUE":0,"DATETIME_CURRENT":"12:02"},
{"FailedCount_MEAS_VALUE":3,"DATETIME_CURRENT":"12:03"},
{"FailedCount_MEAS_VALUE":4,"DATETIME_CURRENT":"12:04"}],
"SucceededCount":[{"SucceededCount_MEAS_VALUE":110},
{"SucceededCount_MEAS_VALUE":120},
{"SucceededCount_MEAS_VALUE":130},
{"SucceededCount_MEAS_VALUE":140}]
}
"AllCount":[{"AllCount_MEAS_VALUE":121},
{"AllCount_MEAS_VALUE":120},
{"AllCount_MEAS_VALUE":133},
{"AllCount_MEAS_VALUE":144}]
{
"FailedCount":[{"FailedCount_MEAS_VALUE":1,"DATETIME_CURRENT":"12:01"},
{"FailedCount_MEAS_VALUE":0,"DATETIME_CURRENT":"12:02"},
{"FailedCount_MEAS_VALUE":3,"DATETIME_CURRENT":"12:03"},
{"FailedCount_MEAS_VALUE":4,"DATETIME_CURRENT":"12:04"}],
"SucceededCount":[{"SucceededCount_MEAS_VALUE":110},
{"SucceededCount_MEAS_VALUE":120},
{"SucceededCount_MEAS_VALUE":130},
{"SucceededCount_MEAS_VALUE":140}],
"AllCount":[{"AllCount_MEAS_VALUE":121},
{"AllCount_MEAS_VALUE":120},
{"AllCount_MEAS_VALUE":133},
{"AllCount_MEAS_VALUE":144}]
}
Answer the question
In order to leave comments, you need to log in
For example, like this:
var list = {
"FailedCount": [{
"FailedCount_MEAS_VALUE": 1,
"DATETIME_CURRENT": "12:01"
}, {
"FailedCount_MEAS_VALUE": 0,
"DATETIME_CURRENT": "12:02"
}, {
"FailedCount_MEAS_VALUE": 3,
"DATETIME_CURRENT": "12:03"
}, {
"FailedCount_MEAS_VALUE": 4,
"DATETIME_CURRENT": "12:04"
}],
"SucceededCount": [{
"SucceededCount_MEAS_VALUE": 110
}, {
"SucceededCount_MEAS_VALUE": 120
}, {
"SucceededCount_MEAS_VALUE": 130
}, {
"SucceededCount_MEAS_VALUE": 140
}]
};
list.AllCount = [];
for (var i = 0; i < list.FailedCount.length; i++){
list.AllCount[i] = {};
list.AllCount[i].AllCount_MEAS_VALUE = parseInt(list.FailedCount[i].FailedCount_MEAS_VALUE) + parseInt(list.SucceededCount[i].SucceededCount_MEAS_VALUE);
}
console.log(list);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question