一、什么是JSon对象?
是对象json;
正如之前在秒解json中所说,{}表示对象,
所以JSONObject是:{'name':'tom'}
同时,
这里的对象Json可以是对象数组json:方法是添加数组Json
{'name':['tome ',' kate']}
例如:
JSONObject jsono=new JSONObject (;
JSONArray jsona=new JSONArray (;
Jona.put('Tom );
Jona.put(Kate ); //['tom ',' kate']
Jono.put('name ',jsona ); //{'name':['tom ',' kate']}
二、什么是JSONArray?
是数组json
正如我之前在秒解json中所说,[]表示数组,
所以JSONArray是['tom ',' kate ','烂长颈鹿' ]; 或[ 1,2,3 ]
此外,这里的数组json可以是数组对象json:方法是添加对象json
[{'name':'tom'},{'name':'kate'}]
例如:
JSONArray jsona=new JSONArray (;
JSONObject jsono1=new JOSNObject (;
JSONObject jsono2=new JSONObject (;
Jono1.put('name ',' tom ' ); //{'name':'tom'}
Jono2.put('name ',' kate ' ); //{'name':'kate'}
Jona.put(JSON1、json2); //[{'name':'tom'},{'name':'tom'}]
3 .两者相结合,对象数组对象JSON : { ' book ' : [ { ' name ' : ' Harry Potter ' },{ ' name ' : ' Potter harrrrrry ' }
创建对象JSON-jsono 1: { ' name ' : ' Harrypotter ' } 3360 jsona1. put (' name ',' Harry Potter ' );
创建对象JSON-jsono 2: { ' name ' : ' potterHarry ' } 3360 JSON a2.put (' name ',' Potter Harry ' );
序列JSON-jsona : [ { ' name ' : ' Harry Potter ' },{ ' name ' : ' Potter Harry ' } ] 3360 jsona.put (jsona1); JSONA.put(JSONA2;
创建对象JSON-jsono : jsono3. put (' book ',jsona );
注:重用JSON array和JSONObject时的第一个最重要的区别是:
JSONArray一个个添加;
JSONObject是一对一对添加的;