JavaScript Object Notation AjaxにおけるJSONの利用

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ではHTTPX-JSON ヘッダを利用して簡単にJSONデータの受渡しができる。


  1. ^ JSON is a lightweight, text-based, language-independent syntax for defining data interchange formats. ECMA-404
  2. ^ Introducing JSON”. json.org. 2008年4月19日閲覧。
  3. ^ a b ongoing by Tim Bray · The Last JSON Spec
  4. ^ Subsume JSON a.k.a. JSON ⊂ ECMAScript · V8
  5. ^ Douglas Crockford: The JSON Saga - YouTube
  6. ^ A JSON value can be an object, array, number, string, true, false, or null. ECMA-404
  7. ^ JSONPath - XPath for JSON”. goessner.net. 2023年6月8日閲覧。
  8. ^ JSONPath Comparison”. cburgmer.github.io. 2024年5月10日閲覧。
  9. ^ JSON Developer's Guide”. Oracle Help Center. 2023年6月8日閲覧。
  10. ^ jovanpop-msft. “JSON Path Expressions - SQL Server”. learn.microsoft.com. 2023年6月8日閲覧。
  11. ^ MySQL :: MySQL 8.0 Reference Manual :: 11.5 The JSON Data Type”. dev.mysql.com. 2023年6月8日閲覧。
  12. ^ PostgreSQL: Documentation: 15: 9.16. JSON Functions and Operators
  13. ^ json-path Output Type — MongoDB Command Line Interface”. mongodb.com. 2023年6月8日閲覧。
  14. ^ Path”. Redis. 2023年6月8日閲覧。
  15. ^ JSON Lines”. jsonlines.org. 2024年7月4日閲覧。
  16. ^ ndjson/ndjson-spec: Specification”. 2024年7月4日閲覧。
  17. ^ Update specification_draft2.md · ndjson/ndjson-spec@c658c26
  18. ^ JSON5 – JSON for Humans”. JSON5. 2023年5月31日閲覧。
  19. ^ YAML is JSON”. 2009年7月22日時点のオリジナルよりアーカイブ。2013年5月15日閲覧。
  20. ^ 3.2.1. Representation Graph - YAML Ain’t Markup Language (YAML™) Version 1.2”. yaml.org. 2013年5月15日閲覧。






固有名詞の分類


英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「JavaScript Object Notation」の関連用語

JavaScript Object Notationのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



JavaScript Object Notationのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
ウィキペディアウィキペディア
All text is available under the terms of the GNU Free Documentation License.
この記事は、ウィキペディアのJavaScript Object Notation (改訂履歴)の記事を複製、再配布したものにあたり、GNU Free Documentation Licenseというライセンスの下で提供されています。 Weblio辞書に掲載されているウィキペディアの記事も、全てGNU Free Documentation Licenseの元に提供されております。

©2024 GRAS Group, Inc.RSS