如何设置作为'对象返回的值?

时间:2016-12-07 13:46:56

标签: javascript node.js object

我有一个例子,它有效。但是,当我试图设置一个对象时,与文本一起返回的值,它不起作用...... 响应和请求(控制台Chrome): 回复:{"error":{"error":{"context":["Context must be of type \"object\

示例会在API中返回:

function etc(input, response) {
  var responseText = null;
  if (!response.output) {
    response.output = {};
  } else {
    return response;
  }
  if (response.xs && response.xs[0]) {
    var x = response.xs[0];

    if (x.confidence >= 0.75) {
      responseText = 'etc etc etc ' + x.x;
    } else if (x.confidence >= 0.5) {
      responseText = 'etc etc etc' + x.x;
    } else {
      responseText = 'etc etc etc';
    }
  }
  response.output.text = responseText;
  return response;
}

我的代码:

 success:function(output, input, response) {
          console.log(output);
         // alert(output.request.number); THIS RETURN THE VALUE BUT I NEED --->
       var responseText = null;
       var outputTest = {};
       outputTest = output.request.number; // THE VALUE I WANT RETURN


       responseText = ("The value is: "+ outputTest);

图片返回(控制台Chrome):

enter image description here

API理解:

enter image description here

我尝试了并且可以使用,但不会在我的API中显示

success:function(output, input, response) {
      console.log(output);
     // alert(output.request.number); THIS THE VALUE I NEED
  var responseText = null;
  var outputTeste = {};
  outputTeste = output.request.number;
  var latestResponse = Api.getResponsePayload();

  var context = latestResponse.context;
  responseText = ("The value is:", + outputTeste);

这次在控制台(Chrome)中返回: enter image description here

1 个答案:

答案 0 :(得分:0)

有效:

String[] elements = new String[] {"Bread","Milk","Cereal","Coffee"};
Random r = new Random();
for(int i=0;i<10;i++)
    Set<String> set = new HashSet<>();
    for (int j=0; j < 4; j++) {
       set.add(elements[r.nextInt(4)]);
    }
    System.out.println(set);
}