jQueryでjson形式の文字列をオブジェクトへ変換方法

サンプルコード
<script type="text/javascript">
var obj = '{“students":[' +
'{“firstName":"yamada","lastName":"darowu" },’ +
'{“firstName":"aizawa","lastName":"darowu" },’ +
'{“firstName":"iikawa","lastName":"darowu" }]}’;

//eval()メソッド
//var obj = eval (“(" + obj + “)");

//JSONメソッド
//obj = jQuery.parseJSON(obj);
obj = JSON.parse(obj);
document.getElementById(“fname").innerHTML=obj.students[1].firstName
document.getElementById(“lname").innerHTML=obj.students[1].lastName
</script>

JavaScript

Posted by arkgame