1.JSON本地文件
{ "total": 2, "rows": [ { "code": 1001, "name": "苹果", "price": 8.00 }, { "code": 1002, "name": "葡萄", "price": 10.00 } ] }
2.属性赋值及获取
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script type="text/javascript" src="jquery-easyui-1.5.1/jquery.min.js"></script> <title></title> </head> <body> <script type="text/javascript"> var obj = new Object(); $.ajax({ type: 'get', url: 'datagridData.json', dataType: 'json', success: function(data) { console.log(JSON.stringify(data.rows)) var str = "price"; $.each(data.rows, function(i, value) { //js对象属性赋值及获取属性值的方式 obj.code = value.code; obj["name"] = value["name"]; obj[str] = value[str]; console.log(obj["code"] + "," + obj.name + "," + obj[str]) }) } }) </script> </body> </html>