将Json数组转换为js对象

时间:2015-07-29 06:27:11

标签: javascript php angularjs

Hello All我想将这个json数组转换为其他格式     [{       “名字”:“9之前”,       “y”:“0”     },{       “名字”:“9-30”,       “y”:“0”     },{       “名称”:“9.30-10.00”,       “y”:“0”     },{       “名称”:“10.00-10.30”,       “y”:null     },{       “名称”:“10.30-11.00”,       “y”:null     },{       “名字”:“超过11”,       “y”:null     }]

[{
  name: "Before 9",
  y: 0
}, {
  name: "9-30",
  y: 0
}, {
  name: "9.30-10.00",
  y: 0
}, {
  name: "10.00-10.30",
  y: null
}, {
  name: "10.30-11.00",
  y: null
}, {
  name: "Over 11",
  y: null
}]

请提供一些java脚本和Angular Js,Php

的解决方案

由于

1 个答案:

答案 0 :(得分:2)

我想首先是json字符串,所以你需要一个Array对象:JSON.parse('[{"name":"Before 9","y":"0"},{"name":"9-30","y":"0"},{"name":"9.30-10.00","y":"0"},{"name":"10.00-10.30","y":null},{"name":"10.30-11.00","y":null},{"name":"Over 11","y":null}]');