「JSON」JSONリテラルからのオブジェクトの作成サンプル
書式
const 変数名 =jsonオブジェクトの定義{属性名:値}
セレクタ.innerHTML =変数名.属性名
使用例
<!DOCTYPE html>
<html>
<body>
<h2>JSONリテラルからのオブジェクトの作成</h2>
<div id="show"></div>
<script>
//jsonオブジェクトの定義
const cftObj = {"name":"test007", "age":35, "addr":null};
//セレクタshowにjsonオブジェクトの属性を表示
document.getElementById("show").innerHTML = cftObj.age;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h2>JSONリテラルからのオブジェクトの作成</h2>
<div id="show"></div>
<script>
//jsonオブジェクトの定義
const cftObj = {"name":"test007", "age":35, "addr":null};
//セレクタshowにjsonオブジェクトの属性を表示
document.getElementById("show").innerHTML = cftObj.age;
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <h2>JSONリテラルからのオブジェクトの作成</h2> <div id="show"></div> <script> //jsonオブジェクトの定義 const cftObj = {"name":"test007", "age":35, "addr":null}; //セレクタshowにjsonオブジェクトの属性を表示 document.getElementById("show").innerHTML = cftObj.age; </script> </body> </html>