Liao Xuefeng Java14Java operation XML and JSON-2JSON-1Json Introduction

JSON is a JavaScript object similar data representation format

  • JavaScript Object Notation
  • In addition to the execution of JavaScript statements
  • Retaining only the data

JSON format:

  • Retaining only UTF-8 encoding
  • You must use double quotes
  • Special characters \ translated "abc \ nxyz \ tend"

JSON Features:

  • Suited for representing hierarchy
  • Simple format, only supports
    * value pairs {..}
    * [...] array
    * String String
    * Number The values (integers and floating point)
    * Boolean Boolean
    * null null
{
    "code": "0",
    "data": {
        "list": [{
            "id": "9387",
            "Person": "张三",
            "patId": 10406240,
            "unitPrice": 2088.5,
            "marry": true,
            "visitStatus": null
        }],
        "totalCount": "153"
    },
    "message": "操作成功"
}

Browser directly support the reading and writing JSON. Because the browser JavaScript method provides JSON.parse () and JSON.stringify (), it can direct a JSON string into a JavaScript object or the JavaScript object is serialized to JSON string, so when developing web applications, used as the data transmission JSON, JavaScript can be used to read and write JSON directly in the browser.

    //JSON String to JavaScript Object
    jsObj = JSON.parse(jsonStr);
    //JavaScript object to JSON string
    jsonStr = JSON.stringify(jsObj);

Because natural for JavaScript JSON reader, so REST API is typically selected as the data transmission format JSON

JSON parsing method of:

  • JSR 353 API
  • Jackson
  • gson
  • fastjson

to sum up:

JSON is a lightweight data representation

  • Simple format
  • Parsing speed
  • For Web applications

Guess you like

Origin www.cnblogs.com/csj2018/p/11391171.html