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

JS怎么取得JSON的键名啊?
JScript code

var jsonObject={
    "firstname":"xiaoming";
    "lastname":"wang";
}


请问js怎么获取键名啊,就是"firstname","lastname"

------解决方案--------------------
JScript code

var jsonObject={
    "firstname":"xiaoming",
    "lastname":"wang"
},keys=[];
for(var p in jsonObject)if(jsonObject.hasOwnProperty(p))keys.push(p);
alert(keys);