zoukankan      html  css  js  c++  java
  • json 拼二维json数组

    js声明数组 以及向数组中添加as移除json数据
    
    JavaScript声明JSON数组的方法:
    
    //部分条件,在数据渲上数据要求是数组格式而非json数组格式,取arrayJson.dataList
    var arrayJson = {'dataList':[]};
    1
    2
    向数组中添加json串
    
    arrayJson.dataList.push({'name':'dataName'});
    1
    移除所有数组中数据
    
    arrayJson.dataList.splice(0,arrayJson.dataList.length);
    1
    一下举栗声明json数组串较为复杂并且灵活的格式。
    
    [
        {
            "dateMonth":"05",
            "hopeMoney":"12000",
            "data":[
                {
                    "brickId":"1",
                    "brickYear":"2017-05-15",
                    "brickWeek":"星期二",
                    "brckInfo":[
                        {
                            "bringMoneyOrExpenditure":"5000",
                            "brickClass":"工资",
                            "brickIcon":"ion-ios-star-outline"
                        },
                        {
                            "bringMoneyOrExpenditure":"-2000",
                            "brickClass":"其他",
                            "brickIcon":"ion-ios-star-outline"
                        }
                    ]
                },
                {
                    "brickId":"1",
                    "brickYear":"2017-05-02",
                    "brickWeek":"星期六",
                    "brckInfo":[
                        {
                            "bringMoneyOrExpenditure":"10000",
                            "brickClass":"工资",
                            "brickIcon":"ion-ios-star-outline"
                        }
                    ]
                }
            ]
        },
        {
            "dateMonth":"04",
            "hopeMoney":"12000",
            "data":[
                {
                    "brickId":"1",
                    "brickYear":"2017-04-15",
                    "brickWeek":"星期一",
                    "brckInfo":[
                        {
                            "bringMoneyOrExpenditure":"5000",
                            "brickClass":"工资",
                            "brickIcon":"ion-ios-star-outline"
                        }
                    ]
                }
            ]
        }
    ]



    //我的应用

    ----注意:引号一定是双引号------想要这种格式
    {"userId":3,"productList":[{"productId":1157,"quantity":3},{"productId":1158,"quantity":1}]}

    var productList_array = {"userId":member_uid,"productList":[]};
    $('.main_div').each(function(){
    product_id = $(this).data('id');
    product_num = parseInt($(this).data('num'));
    productList_array.productList.push({"productId":product_id,"quantity":product_num});
    });
    console.log(productList_array);
    productList_array_jsonstr = JSON.stringify(productList_array);
    console.log(productList_array_jsonstr);
    return false;

      

  • 相关阅读:
    String判空效率比较
    myeclipse数据库逆向hibernate教程
    博客使用说明和我的学习心得(技术路线和书单)
    【小记】go如何判断key是否在map中
    MySQL必知必会笔记——MySQL其他操作
    MySQL必知必会笔记——查询的进阶知识
    MySQL必知必会笔记——查询的基础知识
    MySQL必知必会笔记-Mysql基本操作
    Linux学习笔记:Linux命令之权限管理命令
    Linux学习笔记:用户与用户组
  • 原文地址:https://www.cnblogs.com/pansidong/p/8085978.html
Copyright © 2011-2022 走看看