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 Notationï¼JSONï¼æ ¼å¼çæ¹æ³ãéç©ä»¶ä¸è½è¢«å¼å«æå»ºæ§ï¼èé¤äºå®çå
©åæ¹æ³å±¬æ§ä»¥å¤ï¼æ¬èº«ä¹æ²æç¹å¥çåè½ã
æè¿°
>JavaScript Object Notation
JSON æ¯åºåç©ä»¶ãé£åãæ¸åãå串ã叿å¼ãéæ null çèªæ³ãå®å»ºåºãä½ä¸åæ¼ JavaScriptï¼æäº JavaScript 䏿¯ JSONãèæäº JSON 䏿¯ JavaScriptãè«åè¦ JSON: The JavaScript subset that isn'tã
| JavaScript åå¥ | è JSON çå·®å¥ |
|---|---|
| ç©ä»¶èé£å | 屬æ§åç¨±å¿ é æ¯å å«å¨éå¼èä¸çå串ï¼ç¦æ¢å°¾å¾éèã |
| æ¸å | æ¸åä¸å¯ä»¥ 0 ä½çºéé ï¼å°æ¸é»åé¢å¿
é è³å°æä¸ä½æ¸åï¼ä¸æ¯æ´ NaN å Infinityã |
JSON ç宿´èªæ³
JSON-text = object / array
begin-array = ws %x5B ws ; [ left square bracket
begin-object = ws %x7B ws ; { left curly bracket
end-array = ws %x5D ws ; ] right square bracket
end-object = ws %x7D ws ; } right curly bracket
name-separator = ws %x3A ws ; : colon
value-separator = ws %x2C ws ; , comma
ws = *(
%x20 / ; Space
%x09 / ; Horizontal tab
%x0A / ; Line feed or New line
%x0D ; Carriage return
)
value = false / null / true / object / array / number / string
false = %x66.61.6c.73.65 ; false
null = %x6e.75.6c.6c ; null
true = %x74.72.75.65 ; true
object = begin-object [ member *( value-separator member ) ]
end-object
member = string name-separator value
array = begin-array [ value *( value-separator value ) ] end-array
number = [ minus ] int [ frac ] [ exp ]
decimal-point = %x2E ; .
digit1-9 = %x31-39 ; 1-9
e = %x65 / %x45 ; e E
exp = e [ minus / plus ] 1*DIGIT
frac = decimal-point 1*DIGIT
int = zero / ( digit1-9 *DIGIT )
minus = %x2D ; -
plus = %x2B ; +
zero = %x30 ; 0
string = quotation-mark *char quotation-mark
char = 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+XXXX
escape = %x5C ; \
quotation-mark = %x22 ; "
unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
HEXDIG = 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 a JSONNumber (numbers must contain no whitespace) or JSONString (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® 2027 Language Specification> # sec-json-object> |