「JSON」JSONリテラルからのオブジェクトの作成サンプル

2021年9月7日

書式
const 変数名 =jsonオブジェクトの定義{属性名:値}
セレクタ.innerHTML =変数名.属性名

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!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>

 

JSON

Posted by arkgame