Estoy tratando de asignar a mi metodo javascript en valor de la respuesta http cliente, esta respuesta es teóricamente un objeto JSON tal que.
{"457": {"2": {"value": "53.8", "timestamp": 1534257707}, "3": {"value": "21.9", "timestamp": 1534257707}, "4": {"value": "255.0", "timestamp": 1534257707}, "21": {"value": "996.0", "timestamp": 1534257707}, "1": {"value": "4.15", " timestamp ": 1534257707}," 17 ": {" value ":" 156.99062499999997 "," timestamp ": 1534257707}," 5 ": {" value ":" 37.667 "," timestamp ": 1534257707}," 6 ": {"value": "28.900000000000002", "timestamp": 1534257707}, "8": {"value": "4.28", "timestamp": 1534257707}, "15": {"value": "0.83", " timestamp ": 1534257707}," 10 ": {" value ":" 19.31 "," timestamp ": 1534257707}," 22 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 23 ": {"value": "0.0", "timestamp": 1534257707}, "24": {"value": "0.0", "timestamp": 1534257707}, "26": {"value": "0.0", " timestamp ": 1534257707}," 653 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 657 ": {" value ":" - 98.0 "," timestamp ": 1518420299}," 43 " : {"value": "11.824136243472958", "timestamp": 1534257707}, "42": {"value": "326.54049999999995", "timestamp": 1534257707}}}
Creé un componente en JavaScript para procesar esta información:
Este es mi código en el JavaScript y funciona correctamente, ya que lo he probado programando en otro entorno.
var key = Object.keys (data) [0];
var finalobj = {};
for (var and in data [key]) {
finalobj [e] = {
type: "float"
, value: parseFloat (data [key] [e] .value)
, metadata: {
timestamp: {
value: parseInt (data [key] [e] .timestamp)
, type: "Integer"
}
}
};
}
El problema es que si asigno el campo de la respuesta al campo data no obtengo un valor en la respuesta del for en el campo: JsonOutput.
var data = result_ult_dat;
pero si le asigno manualmente el código, si funciona correctamente, ¿cuál es el problema?, No lo entiendo, el valor de result_ult_dat es el mismo que el que copié. si lo hago asi si funciona.
var data = {"457": {"2": {"value": "53.8", "timestamp": 1534257707}, "3": {"value": "21.9", "timestamp": 1534257707}, " 4 ": {" value ":" 255.0 "," timestamp ": 1534257707}," 21 ": {" value ":" 996.0 "," timestamp ": 1534257707}," 1 ": {" value ":" 4.15 "," timestamp ": 1534257707}," 17 ": {" value ":" 156.99062499999997 "," timestamp ": 1534257707}," 5 ": {" value ":" 37.667 "," timestamp ": 1534257707}," 6 ": {" value ":" 28.900000000000002 "," timestamp ": 1534257707}," 8 ": {" value ":" 4.28 "," timestamp ": 1534257707}," 15 ": {" value ":" 0.83 "," timestamp ": 1534257707}," 10 ": {" value ":" 19.31 "," timestamp ": 1534257707}," 22 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 23 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 24 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 26 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 653 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 657 ": {" value ":" - 98.0 "," timestamp ": 1518420299}, "43": {"value": "11.824136243472958", "timestamp": 1534257707}, "42": {"value": "326.54049999999995", "timestamp": 1534257707}}};
¿Cómo puedo solucionar el problema?
Mi código completo es este: