<script>
var test = { name: "name", age: "12" };
var countrys = {
"newval": [{ "Country_code": "101", "Country_name": "中國" },
{ "Country_code": "102", "Country_name": "美國" }]
};
$(function () {
test.id = "1245";
alert(test.id);
//添加
var c = { "Country_code": "103", "Country_name": "英國" };
countrys.newval.push(c)
alert(countrys.newval[0].Country_name)
//刪除
delete countrys.newval[1];
alert(countrys.newval[0].Country_name)
})
</script>
var str1 = {"name": "apple", "sex": "21"};
// 參數:prop = 屬性,val = 值
function createJson(prop, val) {
// 如果 val 被忽略
if(typeof val === "undefined") {
// 刪除屬性
delete str1[prop];
}
else {
// 添加 或 修改
str1[prop] = val;
}
}
