{
"code": 0,
"msg": null,
"data": {
"pageNum": 1,
"pageSize": 5,
"total": 1,
"pages": 1,
"list": [
{
"pid": "0ccddaed355211e79954005056b233c9",
"sectionId": "1234567",
"tid": "0cb966d1355211e79954005056b233c9",
"first": "1",
"parentId": null,
"title": "五一要事",
"userId": "123456",
"userName": "王俐",
"postLayer": 1,
"status": "0",
"createTime": 1494401186000,
"content": "五一放假通知",
"aids": null,
"attachments": [
{
"aid": "0710f56b355911e79954005056b233c9",
"tid": "0cb966d1355211e79954005056b233c9",
"pid": "0ccddaed355211e79954005056b233c9",
"fileType": "png",
"fileName": "11.png",
"fileSize": 85379,
"downloads": 0,
"attachmentUrl": "201705\\a8ae2dd54f9d4c8aa7ead423f2578992.png",
"downloadUrl": "http://10.144.238.21:8080/starMOOC/forum/downloadFile/0710f56b355911e79954005056b233c9",
"previewUrl": "http://10.144.238.21:8080/starMOOC/forum/showImage/0710f56b355911e79954005056b233c9",
"uploadtime": 1494404183000,
"aids": null
}
]
}
],
"firstPage": 1,
"prePage": 0,
"navigatepageNums": [
1
]
}
}
js读取JSON的方法我接触到的有两种:
方法一:函数构造定义法返回
var strJSON = "{name:‘json name‘}";//得到的JSON
var obj = new Function("return" + strJSON)();//转换后的JSON对象
alert(obj.name);//json name
方法二:js中著名的eval函数
var strJSON = "{name:‘json name‘}";//得到的JSON
var obj = eval( "(" + strJSON + ")" );//转换后的JSON对象
alert(obj.name);//json name
第二种方法需要注意的是,对象表达式{‘name‘:‘json name‘}必须用“()”扩住,否则
var strJSON = "{name:‘json name‘}";
var obj = eval(strJSON);
alert(obj.constructor);//String 构造函数
alert(obj.name);//undefine
必须把对象表达式扩起来eval执行才能生成一个匿名对象!