pentaho object assigned to variable

0

I'm trying to assign my javascript method to the value of the http client response, this response is theoretically a JSON object such that.

{"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}}}

I created a component in JavaScript to process this information:

This is my code in the JavaScript and it works correctly, since I've tried it programming in another environment.

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"
    }
    }
    };
    }

The problem is that if I assign the answer field to the data field I do not get a value in the for answer in the field: JsonOutput.

var data = result_ult_dat;

but if I manually assign the code to it, if it works correctly, what is the problem? I do not understand it, the value of result_ult_dat is the same as the one I copied. if I do it like that if it works.

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}}};

How can I solve the problem?

My complete code is this:

    
asked by Manolait 15.08.2018 в 14:45
source

1 answer

0

I have solved it by adding this to my javascript code and working with object

var objeto = JSON.parse(result_ult_dat);
    
answered by 15.08.2018 в 20:07