封装一个Js 对象 生成Json


<script src="~/Content/Scripts/jquery-1.11.3.min.js"></script>
<script>
    $(function () {

        var data =
            {
                GoThroughNo: "ABC00001",
                AwbList: []
            };


        for (var i = 0; i < 10; i++) {
            var hawbMapping = new Object();
            hawbMapping.Mawb = i;
            hawbMapping.Hawb = i + "001";
            hawbMapping.PictrueUrls = ["http://www.baidu.com/", "http://sina.com.cn"];
            data.AwbList.push(hawbMapping);
        }


        var jsonString = JSON.stringify(data);

        alert(jsonString);
    });
</script>

 

生成的Json如下:

{
    "GoThroughNo": "ABC00001",
    "AwbList": [
        {
            "Mawb": 0,
            "Hawb": "0001",
            "PictrueUrls": [
                "http://www.baidu.com/",
                "http://sina.com.cn"
            ]
        },
        {
            "Mawb": 1,
            "Hawb": "1001",
            "PictrueUrls": [
                "http://www.baidu.com/",
                "http://sina.com.cn"
            ]
        },
        {
            "Mawb": 2,
            "Hawb": "2001",
            "PictrueUrls": [
                "http://www.baidu.com/",
                "http://sina.com.cn"
            ]
        },
        {
            "Mawb": 3,
            "Hawb": "3001",
            "PictrueUrls": [
                "http://www.baidu.com/",
                "http://sina.com.cn"
            ]
        },
        {
            "Mawb": 4,
            "Hawb": "4001",
            "PictrueUrls": [
                "http://www.baidu.com/",
                "http://sina.com.cn"
            ]
        },
        {
            "Mawb": 5,
            "Hawb": "5001",
            "PictrueUrls": [
                "http://www.baidu.com/",
                "http://sina.com.cn"
            ]
        },
        {
            "Mawb": 6,
            "Hawb": "6001",
            "PictrueUrls": [
                "http://www.baidu.com/",
                "http://sina.com.cn"
            ]
        },
        {
            "Mawb": 7,
            "Hawb": "7001",
            "PictrueUrls": [
                "http://www.baidu.com/",
                "http://sina.com.cn"
            ]
        },
        {
            "Mawb": 8,
            "Hawb": "8001",
            "PictrueUrls": [
                "http://www.baidu.com/",
                "http://sina.com.cn"
            ]
        },
        {
            "Mawb": 9,
            "Hawb": "9001",
            "PictrueUrls": [
                "http://www.baidu.com/",
                "http://sina.com.cn"
            ]
        }
    ]
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM