0

JSON コードを javascript/jquery で使用可能な配列に変換しようとしています。

ajax経由で到着する次のJSONコードがあります。

[{"id":"9","firstname":"Greg","surname":"Bril","position":"0","busy":"0","disabled":"0"},{"id":"14","firstname":"Nai","surname":"Brooks","position":"1","busy":"0","disabled":"0"},{"id":"17","firstname":"Margaret","surname":"Grey","position":"1","busy":"0","disabled":"0"},{"id":"1","firstname":"Cameron","surname":"Grover","position":"0","busy":"0","disabled":"0"},{"id":"2","firstname":"Sarah","surname":"Grover","position":"0","busy":"0","disabled":"0"},{"id":"3","firstname":"Margaret","surname":"Hynes","position":"0","busy":"0","disabled":"0"},{"id":"4","firstname":"Stephen","surname":"Hynes","position":"0","busy":"0","disabled":"0"},{"id":"11","firstname":"Ben","surname":"Mills","position":"1","busy":"0","disabled":"0"},{"id":"15","firstname":"Elizabeth","surname":"Mills","position":"1","busy":"0","disabled":"0"},{"id":"10","firstname":"Grant","surname":"Mills","position":"0","busy":"0","disabled":"0"},{"id":"16","firstname":"John","surname":"Mills","position":"1","busy":"0","disabled":"0"},{"id":"13","firstname":"Lucinda","surname":"Ower","position":"1","busy":"0","disabled":"0"},{"id":"12","firstname":"Karina","surname":"Scott","position":"1","busy":"0","disabled":"0"}]

以下を使用して作成および解釈されます。

$.getJSON( "tc_search1.php", {
        leave: $("input#leave").val(),
        end: $("input#end").val(),
        override: $("#tc_override").is(":checked"),
        tc_id: $("#tc_id").val()
    }, function(data) {
         //i cant get this part to work
    });

成功の機能をうまく機能させることができないようです。jquery ドキュメント Web サイトで $.each メソッドを試しましたが、うまくいきません。誰でも助けることができますか?

4

1 に答える 1

0

このgetJSONメソッドは、JSON 文字列を Javascript オブジェクトに自動的に解析します。

成功のコールバック関数のdataパラメーターは、オブジェクトの配列になります。たとえば、式data[0].firstnameは を返し"Greg"ます。

于 2012-08-14T12:43:13.743 に答える