English 中文(简体)
通过诺德.js的回复来遣返JSON。
原标题:Returning JSON via node.js response.write has unexpected results

这里是一个幻灯片:

objects = [];
client.keys  objects* , (err,keys) ->
for (i = 0; i < keys.length; i++){
  client.hgetall(keys[i], function(err, obj) {
    objects.push(obj);
    if (i === keys.length){
      response.writeHead(200, { Content-Type :  application/json });
      console.log(JSON.stringify(objects));
      response.write(JSON.stringify(objects));
      response.end();
    }
  }
}

var objects是一系列物体,通过排泄物重新处置,每个物体有6种特性。 在奥洛尔,我完全了解我的期望。 然而,在客户中,我只收到最后标的阵列。 如果是客户的变压器,我就在菲德尔抓住了它,而现在仍然是有单一目标的阵列。

这里是我通过青少年在青春期获得的东西。 记录:

[{"prop1":"11","prop2":"12","prop3":"13","prop4":"14","prop5":"15","prop6":"16"},  {"prop1":"21","prop2":"22","prop3":"23","prop4":"24","prop5":"25","prop6":"26"},{"prop1":"31","prop2":"32","prop3":"33","prop4":"34","prop5":"35","prop6":"36"},{"prop1":"41","prop2":"42","prop3":"43","prop4":"44","prop5":"45","prop6":"46"},{"prop1":"51","prop2":"52","prop3":"53","prop4":"54","prop5":"55","prop6":"56"},{"prop1":"61","prop2":"62","prop3":"63","prop4":"64","prop5":"65","prop6":"66"}]

我必须做一些错误的事情。

问题回答

你的同文法是错误的。 如果(i = = = 钥匙.length)将永远返回,是因为你正在检查客户。 植被被称为钥匙。 时间长度,而不是电话的填写时间。 相反,应当检查(目标=关键因素)。





相关问题
JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

jQuery quicksearch plug-in tinkering with JSON

I ve implemented the quicksearch plugin by Rik Lomas and I love it for an application in a custom CMS I m building. I was wondering though, since I m going to have a bizillion items in the table if ...

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

PHP json_decode question

i m trying to use json_decode to combine a few json objects and then re-encode it. my json looks like: { "core": { "segment": [ { "id": 7, "...

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string ...

热门标签