1方式一 !("key" in obj)
方式二 obj.hasOwnProperty("key") //obj为json对象。
2获取不确定键的值
for(var key in jsona.data) { alert("对应的值是:" + jsona.data[key].fromName); } var jsona = { "data": { "李梅_7": { "fromId": 7, "toId": 68, "fromName": "李梅", "count": 2, "groupId": null, "groupName": null, "type": 0 }, "gisnew_67": { "fromId": 67, "toId": 68, "fromName": "gisnew", "count": 1, "groupId": null, "groupName": null, "type": 0 } }, "code": 1, "msg": "获取新消息成功!" }