Property access in JSON format-dot or bracket

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.