zoukankan      html  css  js  c++  java
  • 对JSON的增删查改

    原文地址:点击打开链接
    使用JS对Json数据的处理,项目遇到需要对Json数据进行相关操作,比如增删改操作,本以为会比较难,网上搜索下,发现还是比较简单的,贴一段代码:
    <script type="text/javascript">
            var json = {
                "age":24,
                "name":"cst"
            };
            //修改Json中的age值,因为Json中存在age属性
            json["age"] = 30;
            alert(json.age); //30
     
            //增加Json中的sex值,因为Json中不存在sex属性
            json["sex"] = "M";
            alert(json.sex); //M
     
            <!-- 遍历Json中的数据 -->
            for(var key in json){
                try{
                    var value = eval("json['" +  key +"']");
                    alert(key+"_"+value);
                }catch(e){}
            }
     
            //删除Json数据中的age属性
            delete json["age"];
            alert(json.age); //undefined
     
        </script>


  • 相关阅读:
    JavaScript节点属性
    main函数的参数
    CGI
    open()函数 linux中open函数使用
    海伦公式
    C语言字符串操作函数
    makefile(一)
    makefile
    第一天
    时间小憩
  • 原文地址:https://www.cnblogs.com/jiangmy/p/4515418.html
Copyright © 2011-2022 走看看