0

我在Javascript中有这样的JSON:

var json = {
    "total": "100",
    "page":"1",
    "records":"100",
    "rows": [
        {
            "no": "1",
            "part_number": "2",
            "part_name": "3",
            "price": "4",
            "note": "8"
        }
    ]
};

我想添加

"test1":"5",
"test2":"7"

转换成上面的 JSON。

所以它会是这样的:

var json = {
    "total":"100",
    "page":"1",
    "records":"100",
    "rows": [
        {
            "no": "1",
            "part_number": "2",
            "part_name": "3",
            "price": "4",
            "test1": "5",
            "test2": "7",
            "note":"8"
        }
    ]
};
4

2 回答 2

2
json["rows"][0]["test1"] = "5";
json["rows"][0]["test2"] = "7";
于 2013-06-20T14:44:23.210 回答
2

只是:

json.rows[0].test1=5; // or if you want "5"
json.rows[0].test2=7;
于 2013-06-20T14:46:43.407 回答