// 这个是待转的json串
var jstr = "{'a':100,'b':'aaa'}";
// 经过下面语句把这个语句描述的对象数据,赋给这个m对象了
eval ("m = "+ jstr);
// 现在m是个对象,访问它的属性,就直接用m.a就可以了:
document.write("m.a=" + m.a);
document.write("m.a=" + m.a);
就这么简单,别的都是废话:
document.write(dumpObj(m));
function dumpObj(myObject) {
var s = "";
for (var property in myObject) {
s = s + "\n "+property +": " + myObject[property] ;
}
return s;
}
var s = "";
for (var property in myObject) {
s = s + "\n "+property +": " + myObject[property] ;
}
return s;
}