JS修改JSON对象属性名

_tRovi 2014-10-22 07:28:47
var json={ "sports": [
{
"name": "id",
"type": "int",
"length": "10",
"default": "1",
"description": "主键为id"
},
{
"name": "sportsname",
"type": "varchar",
"length": "20",
"default": "1",
"description": "运动名称"
}
],
"color": [
{
"name": "id",
"type": "int",
"length": "10",
"default": "1",
"description": "主键为id"
},
{
"name": "colorName",
"type": "varchar",
"length": "20",
"default": "1",
"description": "颜色名称"
}
]
}
我想用JS把这个JSON对象的color对象名改掉,例如aaa,或者bbb的,找了很多方法都没找到,所以来这里寻求答案
...全文
1297 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tuoluofu2 2016-09-03
  • 打赏
  • 举报
回复
楼主,怎么弄好的求教
_tRovi 2014-10-22
  • 打赏
  • 举报
回复
非常感谢! 终于解决了
slwsss 2014-10-22
  • 打赏
  • 举报
回复
var json={ "sports": [
        {
            "name": "id",
            "type": "int",
            "length": "10",
            "default": "1",
            "description": "主键为id"
        },
        {
            "name": "sportsname",
            "type": "varchar",
            "length": "20",
            "default": "1",
            "description": "运动名称"
        }
    ],
    "color": [
        {
            "name": "id",
            "type": "int",
            "length": "10",
            "default": "1",
            "description": "主键为id"
        },
        {
            "name": "colorName",
            "type": "varchar",
            "length": "20",
            "default": "1",
            "description": "颜色名称"
        }
    ]
}
json.aaa=json.color;
delete json.color;
console.log(json)

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧