1. JSON format-access JSON property names, property values
<script> attr format-dot or bracket-NOTE: the variable var imgdata={"name" can be placed inside the brackets: " Picture description and picture relative path "," title ":" Logo image "," url ":" Logo.png "}; alert (imgdata.name); Alert (imgdata["name"]); var str= "name"; Alert (Imgdata[str]); var json1={"name": "Here is a set of pictures of the text description and picture relative path", "title": ["logo image", "Picture 1", "Picture 2", "Picture 3"], "url": ["Logo.png", "1.png", "2.P Ng "," 3.png "]};alert (json1.name), alert (Json1.url), alert (json1.url[1]), alert (json1[" name "]), alert (JSON 1["url"]), alert (json1["url"][1]), var json2 ={"name": "Picture description and picture relative path", "Imgdata": [{"Name": "Picture 1", "title": "Logo picture 1 "," url ":" Logo1.png "}, {" Name ":" Picture 2 "," title ":" Logo picture 2 "," url ":" Logo2.png "}, {" Name ":" Picture 3 "," title ":" Logo image 3 "," url ":" Logo3.png "}]}; alert (json2.name); alert (json2.imgdata); alert (json2.imgdata[0].name); Alert (json2["name"]); Alert (json2["Imgdata"]); Alert (json2["Imgdata"][0].name); </script>
2.for-in accessing JSON property names, property values
<script> var json1= { "name": "July", "age": 2.png, "imgsrc": ["1.png", "", "3.png"] }; /* For-in Access Property name: Name Age imgsrc*/for (var attr in json1) { console.log (attr); } /* For-in Access attribute value : July ["1.png", "2.png", "3.png"] * /for (Var attr in json1) { Console.log (json1[attr]); } </script>
3.for-in the property name of the Access object, the property value
For-in the property name of the Access object, the property value for the (var attr in window) { console.log ( attr); } for (var attr in window) { console.log ( window[attr]); }
For-in the property name of the Access object, the property value for the (var attr in document) { console.log ( attr); } for (var attr in document) { console.log ( document[attr]); }
Property access in JSON format-dot or bracket