ãWeb-serviceã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã¯XMLãããç¨ãããã¾ãããè¿é ã¯JSONãå¢ãã¦ããã¿ããã§ããJSONã¯XMLã«æ¯ã¹ãã©ã¼ããããåç´ã§ä¼æãã³ã³ãã¯ãã軽éã¤ã³ã¿ã¼ãã§ã¼ã¹ãªã®ã§ã¹ããã®ãããªï¼ãã¹ã¯ãããæ©ããã¯ï¼éåãªã¯ã©ã¤ã¢ã³ãã§ã楽ã«æ±ãã¾ããããããããªããã§C++ã§JSONãæ±ãã¹ããªãµã¼ããå§ãã¾ããã
JSONã®æ§é
ãJSON:JavaScript Object Notationï¼JavaScriptãªãã¸ã§ã¯ãè¨æ³ï¼ãRFC4627ï¼PDFï¼ã§è¦å®ããã¦ãã¾ããè±æã¨ã¯ãã10ãã¼ã¸ã«ãæºããªãå°ããªè¦æ ¼ã§ããããã»ã©ã®è¦å´ããªãç解ã§ãã¾ãã
ããã¼ã¨ãã¾ãJSONã§è¡¨ç¾ã§ããvalueï¼å¤ï¼ã¯ï¼
- booleanï¼çå½å¤ï¼
- numberï¼æ°å¤ï¼
- stringï¼æååï¼
ã®3ã¤ã®åºæ¬åãbooleanã¯trueãfalseãnumberã¯æµ®åå°æ°ç¹ããããdoubleå¤ï¼æ´æ°å¤ã¯ããã¾ããï¼ãstringã¯æåéãã"ãã§å²ã¾ããæååã§ãã
ãããã«æ§é ããã£ãvalueã¨ãã¦ï¼
- arrayï¼é åï¼
- objectï¼ãªãã¸ã§ã¯ãï¼
ãããã¾ããarrayã¯0å以ä¸ã®valueãå å ããé åºåãvalueãã,ãã§åºåããã[ãã¨ã]ãã§å²ã¿ã¾ããobjectã¯ãã¼ã¨å¤ã®çµã並ã¹ããã®ãããããé£æ³é åãããã¯è¾æ¸ã¨å¼ã°ããã¢ã¬ã§ãããã¼ã¯stringãå¤ã¯valueã§ãkey:value ãã,ãã§åºåã£ã¦ä¸¦ã¹ãã{ãã¨ã}ãã§å²ã¿ã¾ãã
ãããã¦ããä¸ã¤ãå¤ãæããªããã¨ï¼ç¡å¹å¤ï¼ã表ãï¼
- null
ãvalueã®ä¸å¡ã§ãã
ããããã®valueãæååã§è¡¨ç¾ããJSON textãä¼æã¨ãã¦ããã¨ããããã®ã§ãããJSON textã¯arrayã¾ãã¯objectã§ãªãã¦ã¯ãªãã¾ãããããã«ãJSON textã¯Unicodeã§ãªãã¦ã¯ãªãã¾ããï¼é常UTF-8ãç¨ãããã¾ãï¼ã
ãRFC4627ã®æ«å°¾ã«ãã£ãJSON textã®ä¸ä¾ï¼example.jsonã以ä¸ã«ç¤ºãã¾ããèªã¿ãããããã«ã¤ã³ãã³ãï¼æ¹è¡ãã¦ãã¾ãããä¼æã¨ãã¦ç¨ããã¨ãã¯ã¡ãã»ã¼ã¸é·ãã±ããããããæ¹è¡ï¼ç©ºç½ãã¯ããã£ã¦ã®ãã®ãã«è©°ãããããã¨ãå¤ãããã§ãã
ãããã¹ãã¨ãã¦ãèªã¿ãããã§ãããé£ç¹ãããã¨ããã°ãã³ã¡ã³ããæ¸ããªãããã¨ã§ãããããã¡ãã»ã¼ã¸ã®ããã¨ããç®çã®è¨æ³ã§ãããããµããèªããã¨ã¯èãã¦ãªãã®ã§ä»æ¹ããªããã¨ã§ã¯ããã¾ããã