ãªã¼ãã¼ããã¼ãã¿ã«ã¹ã¿ãã¯ããã¦ããé(?)ç¨ã®ãªãã«ãã·ã§ã¼åã¸ã®æ¥åé£çµ¡ãããã®ã ãã©ãèãã¦ã¿ãã¨ãããã¯å ¬éå½¢å¼ã§ããªããåé¡ãªãã®ã ãããã£ã¦ããã§ãååããã®æ¥è¨ã«æ¸ãã¾ãï¼ã·ã§ã¼å
JSONããããã
JSONã¯ãç°¡ç¥ã§ä¾¿å©ãªãã©ã¼ããããåã¯XML好ãã ãã©ãç¨éã«ãã£ã¦ã¯JSONã®ã»ããè¯ããã¨ãããã¾ããã¨ãè¨ã£ã¦ãå®ã¯æ§æãåéããã¦ããã®ã ãã©ãï¼ãè¬ç½ªã¨è¨æ£ï¼JSONã®æ§æãééãã¦ãããåç §ï¼ããããããã
JSONå½¢å¼ã®åºæ¬è¡¨ç¾ã¯stringãnumberãbooleanãnullã§ããããå ã«2種é¡ã®æ§é çãã¼ã¿ãçµã¿ç«ã¦ã¾ãããã®2種é¡ã¨ã¯ãªãã¸ã§ã¯ãã¨é åã§ããããªãã¸ã§ã¯ãããé åãã¯ãJavaScriptã«ç±æ¥ããç¨èªæ³ã§ãä¸è¬çã«ã¯ããããï¼ãããã¯ã¬ã³ã¼ãï¼ã¨ãªã¹ãã¨è¨ã£ãã»ããé©åã§ãããã
object ::= '{' '}' | '{' members '}'
members ::= string ':' value | members ',' string ':' valuearray ::= '[' ']' | '[' elements ']'
elements ::= value | elements ',' value
åæ å ±ãæã£ãJSON
XMLã¨JSONã®ããã ã§å¤æãããã©ã¤ãã©ãªãæ¢ã«åå¨ãã¾ããããããèªç¶ãªå¤ææ³ãããããã§ã¯ãªãã¦ãã¿ã°åãå 容ã®JSONã¨ã³ã³ã¼ãã£ã³ã°ã«ã¯ä»å çãªè¦ç´ãå¿ è¦ã§ããä¾ãã°ï¼
<greeting mode="friendly">Hello<smil/></greeting>â ã¿ã°åã¯@tagãå 容ã¯@content
{"@tag" : "greeting",
"mode" : "friendly",
"@content" : ["Hello", {"@tag" : "smile"}]
}
JSONã¨é常ã«ããä¼¼ãï¼äºå®ä¸åãã¨è¨ã£ã¦ããï¼ãã¼ã¿æ§é ï¼ã¨ãã®è¡¨ç¾æ§æï¼ã«ç´ æ§ï¼ãããï¼æ§é ï¼feature structureï¼ãããã¾ããç´ æ§æ§é ã«ã¯ãåä»ãï¼typedï¼ç´ æ§æ§é ã¨å¼ã°ããã¹ã¿ã¤ã«ããã£ã¦ãååãæ·»ãããã¨ãã§ãã¾ãããããªæãï¼
// personãåå
person {
"name" : "ç±³åè±å",
"age" : 23,
"mailAddress" : "hanako-y@hoge.example.jp"
}
XMLã®ã¿ã°åãååã¨ãã¦åä»ãJSONï¼ã¨ããããããå¼ã¶ï¼ã§ã¨ã³ã³ã¼ããããªãï¼
greeting {
"mode" : "friendly",
"@content" : ["Hello", smile{}]
}
ã©ãã§ãã¿ã°
JSONã®æ³¢æ¬å¼§ã®ç´åã«ã¿ã°ï¼ååï¼ãä»å ã§ããã¨ã表ç¾åãå¢ãã¾ãããã¡ããããã¯ãJSONã®ãæ軽ããç°¡ç¥ããæããæ¡å¼µãªã®ã§ããããæªããã¯è°è«ã®ããã¨ããã§ãããã¨ãããããã£ã¦ã¿ãã¨ããæ¹åã§èããã¨ãã¦ï¼ã¿ã°ï¼ååï¼ã¯ãæ³¢æ¬å¼§ï¼ã¤ã¾ããªãã¸ã§ã¯ãï¼ã®åã ããããªãã¦ãè§æ¬å¼§ï¼é åããªã¹ãï¼ãäºéå¼ç¨ç¬¦ï¼æååï¼ãæ°åï¼ç¬¦å·ï¼å°æ°ç¹ï¼æ°å¤ï¼ã®åã«ä»ãã¦ãããã§ããããä¾ãã°ï¼
// å¹³é¢å ã®æãç·
polygonalLine [
point{"x":0, "y":0},
point{"x":1, "y":0},
point{"x":1, "y":2},
point{"x":0, "y":3}
]// personã®é ç®ãåä»ããããªã
person {
"name" : "ç±³åè±å",
"age" : age 23,
"mailAddress" : mail"hanako-y@hoge.example.jp",
"otherContacts" : [tel"03-9999-0000"]
}
ãã¼ã¿åã示åããã¿ã°ã¯çç¥å¯è½ã§ããã®ã¨ãã¯åãæ¨æ¸¬ããï¼ãããã¯äºåã«åãã£ã¦ããï¼ãã¨ã«ãªãã¾ãã
ã¤ãã§ã«ï¼ãããã¯æªã®ãï¼
åãJSONæ§æãåéããã¦ããç®æã¯ããªãã¸ã§ã¯ãï¼ååï¼å¤ãã¢ã®éåï¼ã®ååã«ãå¼ç¨ç¬¦ãå¿ è¦ãªç¹ã§ããååã«ç©ºç½ãç¹æ®æåãå ¥ã£ã¦ãªãï¼ã¤ã¾ããååæååï¼ãªãå¼ç¨ç¬¦ãçç¥ããã»ããæ¸ããããè¦ãããã§ããããããã¨ã空åãç¹æ®ãªååã¨ã¿ãªãã¦æ¬²ããã§ãã*1ãå¼ç¨ç¬¦çç¥ã¨ç©ºãªååã許ãããã¨ã次ã®ãããªè¡¨ç¾ãå¯è½ã§ãã
greeting {
mode : "friendly",
"" : ["Hello", smile{}]
}
ãã¨ãã¨ååããªãã£ãXMLå 容ã®ååãèããå¿ è¦ããªããªãã¾ããç¹å¥ãªååãäºç´ãã¦ãããã®ã§ããããããä¸çªç°¡åãªè§£æ±ºçã§ããããï¼åå空éãèæ ®ããªããªãï¼XMLã¤ã³ã¹ã¿ã³ã¹ã¯èªç¶ã«ãæ¡å¼µããJSONå ã«åãè¾¼ãã¾ãã
ä½ãåé¡ãªã®ãï¼ä½ããããã®ã
ããã¯ããJSONãæ¡å¼µããããã¨ããXMLã®ä»£æ¿æ§æã欲ãããã¨ãã主ããåæ©ã§ã¯ããã¾ããã交æç¨ã®æ§æãé£ãéãã¨å°ã£ããã¨ã«ãªããã²ã©ãç®ã«éãã®ã¯ã¨ã¼ã¯æ¿ç¥ãã¦ã¾ãããã
å¤é¨å½¢å¼ï¼äº¤æå½¢å¼ï¼ã®ããã·ã§ã¯ãªãã®ã§ãããªãã©ã«è¡¨ç¾ã貧弱ãªããã°ã©ãã³ã°è¨èªã§å°ã£ã¦ããã®ãåæ©ã§ãã趣å³çã«ãªãã©ã«ã好ããªãã§ãããç¾å®ã«ããªãã©ã«ä¸è¶³ã¯åé¡ãªãã§ãããã¨ã¼ãã