JavaScript Object Notation
出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2024/07/04 06:23 UTC 版)
AjaxにおけるJSONの利用
AjaxにおいてXMLHttpRequestで非同期にJSONでのデータを受け取る例を示す:
古典的な例
var the_object;
var http_request = new XMLHttpRequest();
http_request.open( "GET", url, true );
http_request.onreadystatechange = function () {
if ( http_request.readyState == 4 ) {
if ( http_request.status == 200 ) {
the_object = eval( "(" + http_request.responseText + ")" );
} else {
alert( "There was a problem with the URL." );
}
http_request = null;
}
};
http_request.send(null);
新しい記法を利用した例
var the_object;
var http_request = new XMLHttpRequest();
http_request.open( "GET", url, true );
http_request.responseType = "json";
http_request.addEventListener ( "load", function ( ev ) {
if ( ev.target.status == 200 ) {
the_object = http_request.response;
} else {
alert( "There was a problem with the URL." );
}
delete http_request;
});
http_request.send(null);
ここでいずれも、http_request
はXMLHttpRequestオブジェクトであり、それを url
にアクセスして返ってきたJSONで記述されたデータを the_object
に格納される。いま、XMLHttpRequestを用いて実装をしたが、iframeなどの他の実装方法もある。また、JavaScriptライブラリのprototype.jsではHTTPの X-JSON
ヘッダを利用して簡単にJSONデータの受渡しができる。
- ^ JSON is a lightweight, text-based, language-independent syntax for defining data interchange formats. ECMA-404
- ^ “Introducing JSON”. json.org. 2008年4月19日閲覧。
- ^ a b ongoing by Tim Bray · The Last JSON Spec
- ^ Subsume JSON a.k.a. JSON ⊂ ECMAScript · V8
- ^ Douglas Crockford: The JSON Saga - YouTube
- ^ A JSON value can be an object, array, number, string, true, false, or null. ECMA-404
- ^ “JSONPath - XPath for JSON”. goessner.net. 2023年6月8日閲覧。
- ^ “JSONPath Comparison”. cburgmer.github.io. 2024年5月10日閲覧。
- ^ “JSON Developer's Guide”. Oracle Help Center. 2023年6月8日閲覧。
- ^ jovanpop-msft. “JSON Path Expressions - SQL Server”. learn.microsoft.com. 2023年6月8日閲覧。
- ^ “MySQL :: MySQL 8.0 Reference Manual :: 11.5 The JSON Data Type”. dev.mysql.com. 2023年6月8日閲覧。
- ^ PostgreSQL: Documentation: 15: 9.16. JSON Functions and Operators
- ^ “json-path Output Type — MongoDB Command Line Interface”. mongodb.com. 2023年6月8日閲覧。
- ^ “Path”. Redis. 2023年6月8日閲覧。
- ^ “JSON Lines”. jsonlines.org. 2024年7月4日閲覧。
- ^ “ndjson/ndjson-spec: Specification”. 2024年7月4日閲覧。
- ^ Update specification_draft2.md · ndjson/ndjson-spec@c658c26
- ^ “JSON5 – JSON for Humans”. JSON5. 2023年5月31日閲覧。
- ^ “YAML is JSON”. 2009年7月22日時点のオリジナルよりアーカイブ。2013年5月15日閲覧。
- ^ “3.2.1. Representation Graph - YAML Ain’t Markup Language (YAML™) Version 1.2”. yaml.org. 2013年5月15日閲覧。
固有名詞の分類
プログラミング言語 |
チューリング完全 Concurrent Prolog JavaScript Object Notation 軽量プログラミング言語 Squeak |
プログラミング言語の構文 |
Abs アリティ JavaScript Object Notation 字下げ NOT NULL制約 |
データシリアライゼーションフォーマット |
Base64 JavaScript Object Notation WDDX Extensible Markup Language Quoted-printable |
- JavaScript Object Notationのページへのリンク