如何更改JSON密钥的名称? [英] How to change name of JSON key?
本文介绍了如何更改JSON密钥的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
children: [
{
name:'Basic Ext Layouts',
expanded: false,
children:[
{
name:'Absolute',
id:'absolute',
leaf:true,
},{
...
}]
}]
是否可以将children
更改为mydata
?
推荐答案
JSON格式只是一个字符串.因此,您可以使用关联的方法来处理JSON字符串. JSON.
JSON format is merely a String in javascript's point of view. So you could manipulate the JSON string with associated method. JSON.
// The original
obj = {
children: [
{
name:'Basic Ext Layouts',
expanded: false,
children:[
{
name:'Absolute',
id:'absolute',
leaf:true,
}]
}]
}
// Transfer the object to a JSON string
var jsonstr = JSON.stringify(obj);
// HERE you do the transform
var new_jsonstr = jsonstr.replace('"children"', '"mydata"');
// You probably want to parse the altered string later
var new_obj = JSON.parse(new_jsonstr);
这篇关于如何更改JSON密钥的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文