如何将函数返回的JS对象转换为字符串? [关闭]

问题描述 投票:0回答:0

我试图将从函数返回的 js 对象转换为 JSON 字符串,但是当我尝试使用 JSON.stringify 时,它总是从对象中删除我的嵌套键值

var json_object = new Object();
json_object = fvp_migration(ver, sites[itr_sites]); // typeof object
console.log(JSON.stringify(json_object)); // removes nested key and values

函数返回:

{
"3.23": {
    "28": 14,
    "34": 13,
    "85": 5,
    "155": 5,
    "268": 32,
    "269": 32,
    "589": 5
},
"2.23": {
    "28": 65,
    "34": 55,
    "85": 34,
    "268": 81,
    "269": 81,
    "318": 1
},
"1.23": {
    "28": 51,
    "34": 51,
    "85": 34,
    "268": 22,
    "269": 22,
    "318": 71,
    "575": 3,
    "589": 20
}

}

JSON.stringify 结果:

{"3.23":{},"2.23":{},"1.23":{}}
javascript
© www.soinside.com 2019 - 2024. All rights reserved.