问题与JSON。解析,不知道为什么不解析所有东西

时间:2022-08-23 00:27:39

I'm developing a web app with Node.js using Sails framework(based on Express) and i'm using a third party image solution called Transloadit (no need to know Transloadit).

我正在开发一个带有Node的web应用。我使用的是一个名为Transloadit的第三方图像解决方案(不需要知道Transloadit)。

Anyway, that's not the problem, i'm been able to implement the Transloadit form and receive the information from their API.

无论如何,这不是问题所在,我能够实现Transloadit表单并从他们的API接收信息。

My problem is that, Transloadit gives me the response as a String, and I need to access the response objects, so i'm using var objRes = JSON.parse(req.body.transloadit); to parse it to an JSON object, and when I console.log(objRes); the object is not correctly parsed, i get this: (see all JSON here https://gist.github.com/kevinblanco/9631085 )

我的问题是,Transloadit将响应作为字符串提供给我,我需要访问响应对象,所以我使用var objRes = JSON.parse(req.body.transloadit);将其解析为JSON对象,当我console.log(objRes)时;对象没有被正确解析,我得到如下结果:(请参见这里的所有JSON)

{
    a bunch of fields here ..... 
    last_seq: 2,
    results: {
        thumb: [
            [
                Object
            ]
        ]
    }
}

And I need the data from the thumb array, my question is, Why is doing that when parsing ?

我需要来自拇指数组的数据,我的问题是,解析时为什么要这么做?

Here's the entire request req.body object: https://gist.github.com/kevinblanco/9628156 as you can see the transloadit field is a string, and I need the data from some of their fields.

这是整个请求请求请求请求请求请求。您可以看到,transloadit字段是一个字符串,我需要从它们的一些字段中获取数据。

Thanks in advance.

提前谢谢。

1 个解决方案

#1


3  

There is nothing wrong with the parsing of the JSON -- in fact there is no problem at all.

解析JSON并没有什么错——实际上根本没有问题。

consol.log limits the depth of what it is printing which is why you are seeing [object] in the output.

康索尔。日志限制了它正在打印的内容的深度,这就是您在输出中看到[object]的原因。

If you want to see the full output in node.js then just use the inspect utility like this;

如果您想在node中看到完整的输出。然后使用像这样的检查工具;

console.log(util.inspect( yourobject, {depth:null} ));

console.log(跑龙套。检查(yourobject {深度:零}));

and that will print the entire content.

它会打印整个内容。

Note that this is just an artifact of console.log printing it.

注意,这只是控制台的产物。日志打印。

#1


3  

There is nothing wrong with the parsing of the JSON -- in fact there is no problem at all.

解析JSON并没有什么错——实际上根本没有问题。

consol.log limits the depth of what it is printing which is why you are seeing [object] in the output.

康索尔。日志限制了它正在打印的内容的深度,这就是您在输出中看到[object]的原因。

If you want to see the full output in node.js then just use the inspect utility like this;

如果您想在node中看到完整的输出。然后使用像这样的检查工具;

console.log(util.inspect( yourobject, {depth:null} ));

console.log(跑龙套。检查(yourobject {深度:零}));

and that will print the entire content.

它会打印整个内容。

Note that this is just an artifact of console.log printing it.

注意,这只是控制台的产物。日志打印。