JSON.stringify不对嵌套数组进行字符串化 [英] JSON.stringify does not stringify nested arrays

查看:705
本文介绍了JSON.stringify不对嵌套数组进行字符串化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在调查为什么JSON.stringify()无法正确解析我的对象.这是我要解析为JSON字符串的对象:

I am currently in investigation why JSON.stringify() does not properly parse my object. This is my object I am trying to parse into a JSON string:

var data = [{
    name: string,
    active: bool,
    data: [
        value: number,
        date: string
    ]
}]

但是,当在对象上调用JSON.stringify()时,我得到的结果与此类似:

However when calling JSON.stringify() on my object, I get a result similar to this:

/* JSON.stringify(data) */
[{
    name: string,
    active: bool,
    data: [
        [Object],
        [Object],
        ...
    ]
}]

JSON.stringify是否有细微差别,导致这种情况发生?如果可以帮助澄清更多细节,我很乐意为我的问题添加更多细节.

Is there a nuance to JSON.stringify that causes this to happen? I'd be happy to add more details to my question if it helps clarify any more details.

推荐答案

我认为您的数据数组应如下所示:

I think your data array should be like this:

var data = [{
name: string,
active: bool,
data: { //Use {} instead of []
    value: number,
    date: string
  }
}]

这篇关于JSON.stringify不对嵌套数组进行字符串化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆