JSON详解

JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。 易于人阅读和编写。同时也易于机器解析和生成。 它基于JavaScript Programming LanguageStandard 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)。
获取账号请求返回的json格式:
{"retcode":0,"result":{"face":567,"birthday":{"month":10,"year":1991,"day":18},"occupation":"幼儿园朋友","phone":"135*******","allow":1,"college":"高校","uin":1140467720,"constel":9,"blood":2,"homepage":"","stat":10,"vip_info":0,"country":"印度","city":"艾藻尔","personal":"我可以接受失败 但无法接受放弃","nick":"迎、接2013","shengxiao":8,"email":"1140467720@qq.com","client_type":41,"province":"","gender":"male","mobile":""}}

  • 值的有序列表(An ordered list of values)。在大部分语言中,它被理解为数组(array)。
这是webQQ登录请求返回的数据,就是json格式的:
ptuiCB('0','0','http://ptlogin4.web2.qq.com/check_sig?pttype=1&uin=1140467720&service=login&nodirect=0&ptsig=dd7LyLqXedO*O2UoQMu2d-HZZVoyavYBFqUkV38XTOA_&s_url=http%3A%2F%2Fweb2.qq.com%2Floginproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&f_url=&ptlang=2052&ptredirect=100&aid=1003903&daid=164&j_later=0&low_login_hour=0®master=0','0','登录成功!', '迎、接2013');


这些都是常见的数据结构。事实上大部分现代计算机语言都以某种形式支持它们。这使得一种数据格式在同样基于这些结构的编程语言之间交换成为可能。

对象是一个无序的“‘名称/值’对”集合。一个对象以“{”(左括号)开始,“}”(右括号)结束。每个“名称”后跟一个“:”(冒号);“‘名称/值’ 对”之间使用“,”(逗号)分隔。

数组是值(value)的有序集合。一个数组以“[”(左中括号)开始,“]”(右中括号)结束。值之间使用“,”(逗号)分隔。

webQQ获取的最近联系人

{"retcode":0,"result":[{"uin":3530995492,"type":0},{"uin":2798415686,"type":1},{"uin":2439469649,"type":0},{"uin":3712076686,"type":0},{"uin":4052286504,"type":0},{"uin":2172973108,"type":0},{"uin":3931011104,"type":0},{"uin":168459122,"type":0},{"uin":709225390,"type":1},{"uin":2835899463,"type":1},{"uin":3196445108,"type":0},{"uin":3440936107,"type":0},{"uin":1372873124,"type":1},{"uin":48081617,"type":0},{"uin":2179863374,"type":0},{"uin":2567602756,"type":0},{"uin":3486629301,"type":0},{"uin":2354684030,"type":0},{"uin":4147298777,"type":0},{"uin":2070425284,"type":0},{"uin":3400415685,"type":0},{"uin":105897316,"type":0},{"uin":2727086236,"type":0},{"uin":3743531771,"type":0},{"uin":1871199307,"type":0},{"uin":1359481725,"type":0},{"uin":590176845,"type":0},{"uin":369090649,"type":0},{"uin":3118742302,"type":0},{"uin":258996627,"type":0},{"uin":1075890671,"type":0},{"uin":357442512,"type":0},{"uin":3415096136,"type":0},{"uin":3525693884,"type":0},{"uin":1882709065,"type":0},{"uin":2875793665,"type":0},{"uin":2424077133,"type":0},{"uin":3027182271,"type":0},{"uin":1704244571,"type":0},{"uin":3073503294,"type":0},{"uin":1795180479,"type":0},{"uin":1844295363,"type":0},{"uin":975922732,"type":0},{"uin":4128939606,"type":0},{"uin":3947281671,"type":0},{"uin":2759876885,"type":0},{"uin":370032855,"type":0},{"uin":3023713830,"type":0},{"uin":2903008852,"type":0},{"uin":1042652886,"type":0},{"uin":2047739307,"type":0},{"uin":3225074106,"type":0},{"uin":392121831,"type":0},{"uin":820851771,"type":0},{"uin":3940411529,"type":0},{"uin":417843659,"type":0},{"uin":3141896568,"type":0},{"uin":4068548333,"type":0},{"uin":2744211889,"type":0},{"uin":283196325,"type":0},{"uin":3575562513,"type":0},{"uin":3520421371,"type":0},{"uin":1246077885,"type":0},{"uin":4060230371,"type":0},{"uin":139490328,"type":0},{"uin":1445870012,"type":0},{"uin":2141576243,"type":0},{"uin":1154814333,"type":0},{"uin":586073674,"type":0},{"uin":1554104770,"type":0},{"uin":3905584152,"type":0},{"uin":4047498182,"type":0},{"uin":2499744737,"type":0},{"uin":2134629631,"type":0},{"uin":2540175527,"type":0},{"uin":564927951,"type":0},{"uin":906675484,"type":0},{"uin":2033369090,"type":0},{"uin":4026318863,"type":0},{"uin":1756819431,"type":0}]}


值(value)可以是双引号括起来的字符串(string)、数值(number)、truefalse、 null、对象(object)或者数组(array)。这些结构可以嵌套。

字符串(string)是由双引号包围的任意数量Unicode字符的集合,使用反斜线转义。一个字符(character)即一个单独的字符串(character string)。

字符串(string)与C或者Java的字符串非常相似。

数值(number)也与C或者Java的数值非常相似。除去未曾使用的八进制与十六进制格式。除去一些编码细节。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值