<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> </head> <script> $.getJSON("http://localhost/json_source.html", function(result){ $.each(result, function(i, field){ console.log(field); }); }); var title; titlename=json.title; document.write(titlename); </script> <body> </body> </html>
jsonデータを読み込んで、オブジェクトのプロパティ(ここではtitle)にアクセスするにはどう直せばいいでしょうか。
console.logで表示されたデータはこんな感じです。
Object{title:A,name:X} Object{title:B,name:Y} Object{title:C,name:X}
Uncaught ReferenceError: json is not defined
とエラーが出ます。
回答1件
あなたの回答
tips
プレビュー