天天看點

JSON -- 輕量級的資料交換語言

JSON -- 輕量級的資料交換語言

JSON(JavaScript Object Notation) 是一種輕量級的資料交換格式。易于人閱讀和編寫。同時也易于機器解析和生成。它基于JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999的一個子集。 JSON采用完全獨立于語言的文本格式,但是也使用了類似于C語言家族的習慣(包括C, C++, C#, Java, JavaScript, Perl, Python等)。這些特性使JSON成為理想的資料交換語言。

JSON建構于兩種結構:

  • “名稱/值”對的集合(A collection of name/value pairs)。不同的語言中,它被了解為對象(object),紀錄(record),結構(struct),字典(dictionary),哈希表(hash table),有鍵清單(keyed list),或者關聯數組 (associative array)。
  • 值的有序清單(An ordered list of values)。在大部分語言中,它被了解為數組(array)。

這些都是常見的資料結構。事實上大部分現代計算機語言都以某種形式支援它們。這使得一種資料格式在同樣基于這些結構的程式設計語言之間交換成為可能。

JSON具有以下這些形式:

對象是一個無序的“‘名稱/值’對”集合。一個對象以“{”(左括号)開始,“}”(右括号)結束。每個“名稱”後跟一個“:”(冒号);“‘名稱/值’ 對”之間使用“,”(逗号)分隔。

JSON -- 輕量級的資料交換語言

數組是值(value)的有序集合。一個數組以“[”(左中括号)開始,“]”(右中括号)結束。值之間使用“,”(逗号)分隔。

JSON -- 輕量級的資料交換語言

值(value)可以是雙引号括起來的字元串(string)、數值(number)、

true

false

null

、對象(object)或者數組(array)。這些結構可以嵌套。

字元串(string)是由雙引号包圍的任意數量Unicode字元的集合,使用反斜線轉義。一個字元(character)即一個單獨的字元串(character string)。

字元串(string)與C或者Java的字元串非常相似。

JSON -- 輕量級的資料交換語言

數值(number)也與C或者Java的數值非常相似。除去未曾使用的八進制與十六進制格式。除去一些編碼細節。

JSON -- 輕量級的資料交換語言

空白可以加入到任何符号之間。 以下描述了完整的語言。

  • ASP:
    • JSON for ASP.
    • JSON ASP utility class.
  • ActionScript:
    • ActionScript1.
    • ActionScript2.
    • ActionScript3.
    • JSONConnector.
  • C.
    • JSON_checker.
    • JSON parser.
    • json-c.
    • M's JSON parser.
    • YAJL.
  • C++:
    • TinyJSON.
    • jsoncpp.
    • zoolib.
    • Jaula.
    • JOST.
    • JSON Spirit.
    • CAJUN.
  • C#:
    • JSON_checker.
    • Jayrock.
    • Json.NET - LINQ to JSON.
    • JSONSharp.
    • LitJSON.
    • JSON for .NET.
    • JsonFx.
    • JsonExSerializer.
    • How do I write my own parser?
  • ColdFusion:
    • ColdFusion 8.
    • CFJSON.
    • toJSON.
  • D.
  • Delphi:
    • Delphi Web Utils.
    • JSON Delphi Library.
    • JSON Toolkit.
  • E.
  • Eiffel.
  • Erlang.
  • Fan.
  • Flex.
  • Haskell:
    • RJson package.
    • json package.
    • JSON.hs.
    • HaskellNet.
  • haXe.
  • Java:
    • org.json.
    • org.json.me.
    • Json-lib.
    • JSON Tools.
    • json-simple.
    • Stringtree.
    • SOJO.
    • VRaptor.
    • Restlet.
    • Jettison.
    • json-taglib.
    • FLEXJSON.
    • XStream.
    • JsonMarshaller.
    • Flexjson.
    • Jackson JSON Processor.
    • JON tools.
    • google-gson.
  • JavaScript:
    • json2.js.
      • Chinese.
    • json_parse.js.
    • json_parser_state.js.
    • json_sans_eval.
  • Lasso.
  • Lisp:
    • Common Lisp
      • Common Lisp JSON.
      • Yason.
    • Emacs Lisp.
    • Chicken Scheme.
    • MZScheme.
    • PLT Scheme.
  • LotusScript:
    • JSON LS.
    • JSON Reader/Writer.
  • Lua:
    • Json4Lua.
    • Json.lua.
  • Objective C:
    • BSJSONAdditions.
    • Cocoa JSON Framework.
  • Objective CAML.
  • OpenLaszlo.
  • Perl.
  • PHP:
    • PHP 5.2.
    • json.
    • Services_JSON.
    • Zend_JSON.
    • JSONRPC.
    • Solar_Json.
    • SCA_SDO.
    • Comparison of php json libraries.
  • Pike:
    • Public.Parser.JSON.
    • Public.Parser.JSON2.
  • pl/sql.
  • PowerShell.
  • Prolog:
    • SWI-Prolog HTTP support
    • json.prolog.
  • Python:
    • The Python Standard Library.
    • simplejson.
    • pyson.
  • R.
  • REALbasic.
  • Rebol.
  • Ruby:
    • json.
    • yajl-ruby.
  • Squeak.
  • Tcl.
  • Visual Basic.
  • Visual FoxPro.
  • RFC 4627 application/json.
  • The

    <module>

    Tag.
  • JSONRequest.
  • JSONRequest Extension for Firefox.
  • The Fat-free Alternative to XML
  • An example of JSON-encoded messages.
  • The JSON Group on Yahoo!
  • Yahoo! JSON
  • Google Data
  • GeoJSON
  • JSON shell for the browser
  • JSONT.
  • JSON Template.
  • JSONPath.
  • JPath.
  • Jaql: A JSON Query Language.
  • JSPON.
  • JsonML.
  • CSS JSON.
  • JSON 2 HTML.
  • XSLTJSON.
  • xml2json-xslt.
  • x-xml2jsonphp.
  • Parsing JSON into XQuery.
  • Pure.
  • JSON.com.
  • JSON-RPC.
  • JSON-RPC-Page.
  • jabsorb.
  • JSON-Cache.
  • CouchDB.
  • DBSlayer.
  • Persevere.
  • SpringDB.
  • StrokeDB.
  • JSONLint, The JSON Validator.
  • JSLint, Syntax Checker.

Why JSON isn't just for JavaScript • I can't believe it's not XML! • The JSON vs XML debate begins in earnest • JSON and XML • JSON vs. XML as a data interchange format • Examining JSON • JSON and .Net • Shaping the future of secure Ajax mashups • JSON and Browser Security

繼續閱讀