-2

サーバーからのオブジェクトのリストである次のデータを解析したいと思います。JSON.stringify(data.d);これは、データを使用した後のものです。

"[{"__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"}]"

これは、属性として empProperty、empValue、isValid、コメントで構成される CellData のリストです。JS でこれらのプロパティにアクセスできません。

4

3 に答える 3

2

いくつかのコメントで述べたように、data.d[i].empProperty と data.d[i].empValue の使用を開始するだけです。i は配列のインデックスです。文字列化しないでください。すでにオブジェクトに解析されています。

JSONについてはこちら

于 2013-03-12T13:48:34.623 に答える
-1

次のリンクからセクションを引用します:JSON

これを防ぐには、JSONパーサーを使用する必要があります。JSONパーサーはJSONテキストのみを認識し、すべてのスクリプトを拒否します。

var jsonData = JSON.stringify(data.d);
var myObject = JSON.parse(jsonData);
于 2013-03-12T13:29:24.133 に答える
-1

構造体はオブジェクトの配列です。したがって、インデックスを介して各要素に簡単にアクセスできます。

var arr = JSON.stringify(data.d);
var item = arr[0];

次に、さまざまな方法で各プロパティにアクセスできます。

empValue = item.empValue;  //returns "a"
empProperty = item["empProperty"];  //returns "SSN"

はこちら

于 2013-03-12T13:25:26.107 に答える