У меня есть функция, которая должна изменять некоторые значения объекта, у которого есть несколько объектов массива.
Этот объект:
{"avg":{"00:00":[],"01:00":[],"02:00":[],"03:00":[],"04:00":[],"05:00":[],"06:00":[],"07:00":[],"08:00":[],"09:00":[],"10:00":[],"11:00":[],"12:00":[],"13:00":[],"14:00":[],"15:00":[],"16:00":[],"17:00":[],"18:00":[],"19:00":[],"20:00":[],"21:00":[],"22:00":[],"23:00":[]},"avg_hum":{"00:00":[],"01:00":[],"02:00":[],"03:00":[],"04:00":[],"05:00":[],"06:00":[],"07:00":[],"08:00":[],"09:00":[],"10:00":[],"11:00":[],"12:00":[],"13:00":[],"14:00":[],"15:00":[],"16:00":[],"17:00":[],"18:00":[],"19:00":[],"20:00":[],"21:00":[],"22:00":[],"23:00":[]},"max":{"00:00":[],"01:00":[],"02:00":[],"03:00":[],"04:00":[],"05:00":[],"06:00":[],"07:00":[],"08:00":[],"09:00":[],"10:00":[],"11:00":[],"12:00":[],"13:00":[],"14:00":[],"15:00":[],"16:00":[],"17:00":[],"18:00":[],"19:00":[],"20:00":[],"21:00":[],"22:00":[],"23:00":[]},"min":{"00:00":[],"01:00":[],"02:00":[],"03:00":[],"04:00":[],"05:00":[],"06:00":[],"07:00":[],"08:00":[],"09:00":[],"10:00":[],"11:00":[],"12:00":[],"13:00":[],"14:00":[],"15:00":[],"16:00":[],"17:00":[],"18:00":[],"19:00":[],"20:00":[],"21:00":[],"22:00":[],"23:00":[]},"max_hum":{"00:00":[],"01:00":[],"02:00":[],"03:00":[],"04:00":[],"05:00":[],"06:00":[],"07:00":[],"08:00":[],"09:00":[],"10:00":[],"11:00":[],"12:00":[],"13:00":[],"14:00":[],"15:00":[],"16:00":[],"17:00":[],"18:00":[],"19:00":[],"20:00":[],"21:00":[],"22:00":[],"23:00":[]},"min_hum":{"00:00":[],"01:00":[],"02:00":[],"03:00":[],"04:00":[],"05:00":[],"06:00":[],"07:00":[],"08:00":[],"09:00":[],"10:00":[],"11:00":[],"12:00":[],"13:00":[],"14:00":[],"15:00":[],"16:00":[],"17:00":[],"18:00":[],"19:00":[],"20:00":[],"21:00":[],"22:00":[],"23:00":[]},"beginDate":"","endDate":""}
И мне нужно добавить значения в массивы (например,: {"00:00": [25], ...})
Итак, я попробовал что-то вроде ("data_raw" - полученный объект):
ArrayNode array = mapper.createArrayNode();
array = (ArrayNode) data_raw.get("avg").get("00:00");
array.add((double) 25.11666711171468);
System.out.println("data_raw: " + data_raw.toString());
Ирезультат (объект "data_raw"):
data_raw: {"avg":{"00:00":[25.11666711171468],"01:00":[],"02:00":[],"03:00":[],"04:00":[],"05:00":[],"06:00":[],"07:00":[],"08:00":[],"09:00":[],"10:00":[],"11:00":[],"12:00":[],"13:00":[],"14:00":[],"15:00":[],"16:00":[],"17:00":[],"18:00":[],"19:00":[],"20:00":[],"21:00":[],"22:00":[],"23:00":[]},"avg_hum":{"00:00":[25.11666711171468],"01:00":[],"02:00":[],"03:00":[],"04:00":[],"05:00":[],"06:00":[],"07:00":[],"08:00":[],"09:00":[],"10:00":[],"11:00":[],"12:00":[],"13:00":[],"14:00":[],"15:00":[],"16:00":[],"17:00":[],"18:00":[],"19:00":[],"20:00":[],"21:00":[],"22:00":[],"23:00":[]},"max":{"00:00":[25.11666711171468],"01:00":[],"02:00":[],"03:00":[],"04:00":[],"05:00":[],"06:00":[],"07:00":[],"08:00":[],"09:00":[],"10:00":[],"11:00":[],"12:00":[],"13:00":[],"14:00":[],"15:00":[],"16:00":[],"17:00":[],"18:00":[],"19:00":[],"20:00":[],"21:00":[],"22:00":[],"23:00":[]},"min":{"00:00":[25.11666711171468],"01:00":[],"02:00":[],"03:00":[],"04:00":[],"05:00":[],"06:00":[],"07:00":[],"08:00":[],"09:00":[],"10:00":[],"11:00":[],"12:00":[],"13:00":[],"14:00":[],"15:00":[],"16:00":[],"17:00":[],"18:00":[],"19:00":[],"20:00":[],"21:00":[],"22:00":[],"23:00":[]},"max_hum":{"00:00":[25.11666711171468],"01:00":[],"02:00":[],"03:00":[],"04:00":[],"05:00":[],"06:00":[],"07:00":[],"08:00":[],"09:00":[],"10:00":[],"11:00":[],"12:00":[],"13:00":[],"14:00":[],"15:00":[],"16:00":[],"17:00":[],"18:00":[],"19:00":[],"20:00":[],"21:00":[],"22:00":[],"23:00":[]},"min_hum":{"00:00":[25.11666711171468],"01:00":[],"02:00":[],"03:00":[],"04:00":[],"05:00":[],"06:00":[],"07:00":[],"08:00":[],"09:00":[],"10:00":[],"11:00":[],"12:00":[],"13:00":[],"14:00":[],"15:00":[],"16:00":[],"17:00":[],"18:00":[],"19:00":[],"20:00":[],"21:00":[],"22:00":[],"23:00":[]},"beginDate":"","endDate":""}
Я ожидаю, что будет изменено только "avg": {"00:00": [X], ...}, но все объекты с "00": 00 "имя заменяется независимо от выбранного" основного поля ":" avg ".
Может ли кто-нибудь мне помочь?
РЕДАКТИРОВАТЬ:
Полный связанный код:
String[] name_db_data = {"avg", "avg_hum", "max", "min", "max_hum", "min_hum"};
SimpleDateFormat hourFormatted = new SimpleDateFormat("HH:mm");
reType = reportType.detailedDailyReport;
ResultSet rs = stm.executeQuery(query); // The String "query" is a dynamic MySQL query.
while(rs.next())
{
if(reType == reportType.detailedDailyReport)
{
int count4 = 0;
Calendar c = Calendar.getInstance();
c.setTime(rs.getTime("hour"));
for(count4 = 0; count4 < name_db_data.length; count4 ++)
{
ArrayNode array_aux2 = mapper.createArrayNode();
array_aux2 = (ArrayNode) data_raw.get(name_db_data[count4]).get(hourFormatted.format(c.getTime()));
array_aux2.add(rs.getDouble(name_db_data[count4]));
}
}