返回空值时,JSON.stringify日期转换为JSON.parse

问题描述 投票:-2回答:1

我有一个对象使用JSON.stringify()转换为json字符串然后我需要使用相同的对象与JSON.parse(),但我得到数组值为空,如何获取原始数据,请帮助解决这个问题,在下面的代码中是stringify数据

{
"agefrom":18,
"ageto":60,
"heightfrom":"1",
"heightto":"28",
"steps":["Never","One"],
"number":["One","two "],
"education":["B.E","B.E / B.Tech"]
}

转换成JSON.parse之后的数据

 {
        "agefrom":18,
        "ageto":60,
        "heightfrom":"1",
        "heightto":"28",
        "steps":"",
        "number":"",
        "education":""
   }
javascript json angular stringify
1个回答
1
投票

fiddle尝试这个小提琴。这对我来说可以。

 a = {
  "agefrom": 18,
  "ageto": 60,
  "heightfrom": "1",
  "heightto": "28",
  "steps": ["Never", "One"],
  "number": ["One", "two "],
  "education": ["B.E", "B.E / B.Tech"]
}
a = JSON.stringify(a)
document.write(a);
b = JSON.parse(a);
document.write(JSON.stringify(b))
© www.soinside.com 2019 - 2024. All rights reserved.