<script type="text/javascript">
var json = {
"age":24,
"name":"cst"
};
//修改Json中的age值,因为Json中存在age属性
json["age"] = 30;
document.writeln(json.age+"<br>"); //30
//增加Json中的sex值,因为Json中不存在sex属性
json["sex"] = "M";
document.writeln(json.sex+"<br>"); //M
<!-- 遍历Json中的数据 -->
document.writeln("添加后开始遍历Json<br>");
for(var key in json){
try{
//var value = eval("json['" + key +"']");
var value = json[key];
document.writeln(key+"_"+value+"<br>");
}catch(e){}
}
//删除Json数据中的age属性
delete json["age"];
document.writeln(json.age); //undefined
</script>
Json 增 删 改
最新推荐文章于 2022-02-16 21:27:09 发布