weixin_44224366
江东周小川
采纳率71.4%
2019-12-18 09:28

php 或 js 将json数据或数组改成自己想要的格式

5
已采纳

新手上路,请问大神们,这样的json数据如何改成下面第二种我想要的格式。

[{
    "DATE": "2019-11-11 11:04:31",
    "CRXS1": "0 "
}, {
    "DATE": "2019-11-11 11:40:50",
    "CRXS1": "0 "
}, {
    "DATE": "2019-11-15 11:03:29",
    "CRXS1": "0 "
}, {
    "DATE": "2019-11-15 11:04:29",
    "CRXS1": "0 "
}, {
    "DATE": "2019-11-15 11:05:29",
    "CRXS1": "0 "
}]

改成这样的格式:

[{
        value: [
            "2019-11-11 11:04:31",
            0
        ]
    },
    {
        value: [
            "2019-11-11 11:40:50",
            0
        ]
    },
    {
        value: [
            "2019-11-15 11:03:29",
            0
        ]
    },
    {
        value: [
            "2019-11-15 11:04:29",
            0
        ]
    },
    {
        value: [
            "2019-11-15 11:05:29",
            0
        ]
    }
]

用php或js都行。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • u010279990 放逐的程序猿 2年前

    这还不简单,直接循环遍历就OK啦

    let arr = [{
        "DATE": "2019-11-11 11:04:31",
        "CRXS1": "0 "
    }, {
        "DATE": "2019-11-11 11:40:50",
        "CRXS1": "0 "
    }, {
        "DATE": "2019-11-15 11:03:29",
        "CRXS1": "0 "
    }, {
        "DATE": "2019-11-15 11:04:29",
        "CRXS1": "0 "
    }, {
        "DATE": "2019-11-15 11:05:29",
        "CRXS1": "0 "
        }]
    
    let temp=[]
    arr.forEach(item => {
        temp.push({
            value:[item.DATE,item.CRXS1]
        })
    })
    console.log(temp)
    
    点赞 评论 复制链接分享
  • dashicaineng 蔡能教授,网站特聘专家 2年前