我想分析以下數據,這是來自服務器的對象列表。這是我有我的數據使用JSON.stringify(data.d);
後:Javascript:解析JSON對象
"[{"__type":"EditGridDemo.CellData","empProperty":"SSN","empValue":"a","isValid":false,"comments":"Reason of what went wrong"},{"__type":"EditGridDemo.CellData","empProperty":"Birth_Date","empValue":"","isValid":false,"comments":"Reason of what went wrong"},{"__type":"EditGridDemo.CellData","empProperty":"Department_Name","empValue":"","isValid":false,"comments":"Reason of what went wrong"},{"__type":"EditGridDemo.CellData","empProperty":"email","empValue":"","isValid":false,"comments":"Reason of what went wrong"},{"__type":"EditGridDemo.CellData","empProperty":"First_Name","empValue":"","isValid":false,"comments":"Reason of what went wrong"},{"__type":"EditGridDemo.CellData","empProperty":"Sex","empValue":"","isValid":false,"comments":"Reason of what went wrong"},{"__type":"EditGridDemo.CellData","empProperty":"Strata_ID","empValue":null,"isValid":false,"comments":"Reason of what went wrong"},{"__type":"EditGridDemo.CellData","empProperty":"SSN","empValue":"b","isValid":false,"comments":"Reason of what went wrong"},{"__type":"EditGridDemo.CellData","empProperty":"Birth_Date","empValue":"","isValid":false,"comments":"Reason of what went wrong"},{"__type":"EditGridDemo.CellData","empProperty":"Department_Name","empValue":"","isValid":false,"comments":"Reason of what went wrong"},{"__type":"EditGridDemo.CellData","empProperty":"email","empValue":"","isValid":false,"comments":"Reason of what went wrong"},{"__type":"EditGridDemo.CellData","empProperty":"First_Name","empValue":"","isValid":false,"comments":"Reason of what went wrong"},{"__type":"EditGridDemo.CellData","empProperty":"Sex","empValue":"","isValid":false,"comments":"Reason of what went wrong"},
{"__type":"EditGridDemo.CellData","empProperty":"Strata_ID","empValue":null,"isValid":false,"comments":"Reason of what went wrong"}]"
這是CellData,其中包括列表empProperty,empValue,isValid方法,評價其attributes..I不能夠訪問這些屬性JS。
解析它會對其進行字符串化。你爲什麼首先把它串起來? – Quentin 2013-03-12 13:22:16
以前,我在做$ .parseJSON(data.d),它給了undefined .. – faizanjehangir 2013-03-12 13:23:28
你爲什麼要解析已經是JavaScript對象的東西?只需使用'data.d'。 – Quentin 2013-03-12 13:24:01