Pentaho Javacriot代码变量对象

时间:2018-08-15 10:45:02

标签: pentaho pentaho-data-integration

我正在尝试使用我的其余客户端方法的响应来导航我的对象,从理论上讲,该响应是这样的JSON对象。

 private string GetData()
 {
     var task = GetDataAsync();
     task.Wait();
     return task.Result;
 }
 private async Task<string> GetDataAsync()
 {
     return "Hello";
 }

我已经在JavaScript中创建了一个组件来处理这些数据:

这是我在Java脚本中的代码,并且可以正常运行,因为我已经尝试过在其他环境中对其进行编程。

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

问题在于,如果我将其分配给该字段,则会按如下所示为答案的值加上日期:

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

当我抛出代码时,它不起作用,但是如果我手动将代码分配给它,如果它正确地工作,这是什么问题呢?我不理解,result_ult_dat的值与一个相同我复制的内容,必须进行转换或类似以下操作:

var data = result_ult_dat;

如何解决此问题。

我的完整代码是这样:

Pentaho codigo

非常感谢您。

Edit01

这是我的完整设计,因为您可以看到数据的值与我的http客户端的响应相同。

Complego1

回答是否通过变量传递

String

有趣的是,当必须将JSONOutPut转换为{}时。

completo

当我尝试将答案放入数据变量(如果可行)时,请看。

Funciona

我不明白为什么

1 个答案:

答案 0 :(得分:0)

我已经解决了这一问题,方法是将其添加到我的javascript代码中并使用对象

var object = JSON.parse (result_ult_dat);