zoukankan      html  css  js  c++  java
  • Array JSON

    W3Schools.com

    Tool: Online jsonviewer

    JSON: JavaScript Object Notation.

    JSON is a syntax for storing and exchanging data.

    JSON Objects

    JSON objects are written inside curly braces.

    {"name":"John", "age":25, "japanese":false}

    JSON Arrays

    JSON arrays are written inside square brackets.

    "employees":[
        {"firstName":"John", "lastName":"Doe"},
        {"firstName":"Anna", "lastName":"Smith"},
        {"firstName":"Peter","lastName":"Jones"}
    ]

    JSON Uses JavaScript Syntax

    var employees = [
        {"firstName":"John", "lastName":"Doe"},
        {"firstName":"Anna", "lastName":"Smith"},
        {"firstName":"Peter","lastName": "Jones"}
    ]; 

    Be accessed:

    // returns John Doe
    employees[0].firstName + " " + employees[0].lastName;
    
    // returns John Doe
    employees[0]["firstName"] + " " + employees[0]["lastName"];

    Be modified

    employees[0].firstName = "Gilbert";
    
    employees[0]["firstName"] = "Gilbert";

    Object From String: Create a JavaScript string containing JSON syntax

    var text = '{ "employees" : [' +
    '{ "firstName":"John" , "lastName":"Doe" },' +
    '{ "firstName":"Anna" , "lastName":"Smith" },' +
    '{ "firstName":"Peter" , "lastName":"Jones" } ]}';

    The JavaScript function JSON.parse(text) can be used to convert a JSON text into a JavaScript object:

    // Normal browsers
    var obj = JSON.parse(text);
    // Older browsers
    var obj = eval ("(" + text + ")");
    // Output
    obj.employees[1].firstName + " " + obj.employees[1].lastName

    以上です

  • 相关阅读:
    弹飞绵羊
    POJ 3308
    狼抓兔子
    块状链表题*1
    块状链表
    双向链表
    Linux入职基础-1.2_U盘安装RedHat5具体步骤
    Linux入职基础-1.1_国内开源的主要镜像站
    VS.NET(C#)--2.9_HTML服务器控件案例
    VS2015按钮方法
  • 原文地址:https://www.cnblogs.com/hzj680539/p/5052074.html
Copyright © 2011-2022 走看看