1. 程式人生 > >封裝一個Js 對象 生成Json

封裝一個Js 對象 生成Json

sina baidu true json min style func push jquer

<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" ] } ] }

封裝一個Js 對象 生成Json