日期:2014-05-16  浏览次数:20415 次

javascript 对象转换 json 的插件

下载地址:http://code.google.com/p/jquery-json/

之前写了篇C#后台声明JSON的文章,今天在写个前端声明JSON的,呵呵

http://www.cnblogs.com/linfei721/archive/2013/04/27/3046822.html

多行模式:

var json = new Array();
for (var i = 8; i < 11; i++) {
  json.push({ name: "linfei" + i, age: (i + 20), address: "武汉" });
}

$(":text").val($.toJSON(json));

显示结果:

[
    {
        "name": "linfei8",
        "age": 28,
        "address": "武汉"
    },
    {
        "name": "linfei9",
        "age": 29,
        "address": "武汉"
    },
    {
        "name": "linfei10",
        "age": 30,
        "address": "武汉"
    }
]

多行多对象模式

var json = new Array();
for (var i =