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

时间:2019-03-10 12:51:34

标签: javascript json angular stringify

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

{
"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":""
   }

1 个答案:

答案 0 :(得分: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))