Movatterモバイル変換


[0]ホーム

URL:


  1. 給開發者的 Web 技術文件
  2. JavaScript
  3. JavaScript 參考文件
  4. 標準內建物件
  5. JSON

此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。

View in EnglishAlways switch to English

JSON

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

* Some parts of this feature may have varying levels of support.

JSON 物件包含了解析、或是轉換為JavaScript Object NotationJSON)格式的方法。這物件不能被呼叫或建構;而除了它的兩個方法屬性以外,本身也沒有特別的功能。

描述

JavaScript Object Notation

JSON 是序列物件、陣列、數字、字串、布林值、還有null 的語法。它建基、但不同於 JavaScript:有些 JavaScript 不是 JSON、而有些 JSON 不是 JavaScript。請參見JSON: The JavaScript subset that isn't

JavaScript 型別與 JSON 的差別
物件與陣列屬性名稱必須是包含在雙引號中的字串;禁止尾後逗號
數字數字不可以 0 作為開頭;小數點前面必須至少有一位數字;不支援NaNInfinity

JSON 的完整語法

JSON-text = object / arraybegin-array     = ws %x5B ws  ; [ left square bracketbegin-object    = ws %x7B ws  ; { left curly bracketend-array       = ws %x5D ws  ; ] right square bracketend-object      = ws %x7D ws  ; } right curly bracketname-separator  = ws %x3A ws  ; : colonvalue-separator = ws %x2C ws  ; , commaws = *(     %x20 /              ; Space     %x09 /              ; Horizontal tab     %x0A /              ; Line feed or New line     %x0D                ; Carriage return     )value = false / null / true / object / array / number / stringfalse = %x66.61.6c.73.65   ; falsenull  = %x6e.75.6c.6c      ; nulltrue  = %x74.72.75.65      ; trueobject = begin-object [ member *( value-separator member ) ]         end-objectmember = string name-separator valuearray = begin-array [ value *( value-separator value ) ] end-arraynumber = [ minus ] int [ frac ] [ exp ]decimal-point = %x2E       ; .digit1-9 = %x31-39         ; 1-9e = %x65 / %x45            ; e Eexp = e [ minus / plus ] 1*DIGITfrac = decimal-point 1*DIGITint = zero / ( digit1-9 *DIGIT )minus = %x2D               ; -plus = %x2B                ; +zero = %x30                ; 0string = quotation-mark *char quotation-markchar = unescaped /    escape (        %x22 /          ; "    quotation mark  U+0022        %x5C /          ; \    reverse solidus U+005C        %x2F /          ; /    solidus         U+002F        %x62 /          ; b    backspace       U+0008        %x66 /          ; f    form feed       U+000C        %x6E /          ; n    line feed       U+000A        %x72 /          ; r    carriage return U+000D        %x74 /          ; t    tab             U+0009        %x75 4HEXDIG )  ; uXXXX                U+XXXXescape = %x5C              ; \quotation-mark = %x22      ; "unescaped = %x20-21 / %x23-5B / %x5D-10FFFFHEXDIG = DIGIT / %x41-46 / %x61-66   ; 0-9, A-F, or a-f       ; HEXDIG equivalent to HEXDIG rule in [RFC5234]DIGIT = %x30-39            ; 0-9      ; DIGIT equivalent to DIGIT rule in [RFC5234]

Insignificant whitespace may be present anywhere except within aJSONNumber (numbers must contain no whitespace) orJSONString (where it is interpreted as the corresponding character in the string, or would cause an error). The tab character (U+0009), carriage return (U+000D), line feed (U+000A), and space (U+0020) characters are the only valid whitespace characters.

方法

JSON.parse()

解析 JSON 字串,能改變給定值和屬性、接著回傳解析值。

JSON.stringify()

回傳給定的 JSON 對應字串,可自行決定只想包括哪些特定屬性、或替換的屬性值。

規範

Specification
ECMAScript® 2026 Language Specification
# sec-json-object

瀏覽器相容性

參見

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp