-
使用Map實現(xiàn)Json private static void createJsonByMap(){ Map<String, Object> wangxiaoer=new HashMap<String,Object>(); Object nullObj = null; wangxiaoer.put("name", "王小二"); wangxiaoer.put("age", 25.2); wangxiaoer.put("birthday", "1990-01-01"); wangxiaoer.put("school", "藍(lán)翔"); wangxiaoer.put("major", new String[] { "理發(fā)", "挖掘機(jī)" }); wangxiaoer.put("has_girlfriend", false); wangxiaoer.put("car", nullObj); wangxiaoer.put("house", nullObj); wangxiaoer.put("comment", "這是一個注釋"); System.out.println(new JSONObject(wangxiaoer).toString()); }
查看全部 -
引入依賴 ? ?<dependency> ? ? ?<groupId>org.json</groupId> ? ? ?<artifactId>json</artifactId> ? ? ?<version>20090211</version> ? ?</dependency> 使用JsonObject實現(xiàn)Json package json; import org.json.JSONException; import org.json.JSONObject; public class JSONObjectSample { public static void main(String[] args) { // TODO 自動生成的方法存根 JSONObject(); } private static void JSONObject() { // TODO 自動生成的方法存根 JSONObject wangxiaoer = new JSONObject(); Object nullObj = null; try { wangxiaoer.put("name", "王小二"); wangxiaoer.put("age", 25.2); wangxiaoer.put("birthday", "1990-01-01"); wangxiaoer.put("school", "藍(lán)翔"); wangxiaoer.put("major", new String[] { "理發(fā)", "挖掘機(jī)" }); wangxiaoer.put("has_girlfriend", false); wangxiaoer.put("car", nullObj); wangxiaoer.put("house", nullObj); wangxiaoer.put("comment", "這是一個注釋"); System.out.println(wangxiaoer.toString()); } catch (JSONException e) { // TODO: handle exception e.printStackTrace(); } } }
查看全部 -
{
?“name”:"王小二",
?“age”:25,
?"birthday":"1994-01-01",
?"school":"北大藍(lán)翔",
?"major":["理發(fā)","挖掘機(jī)"],
"has_girlfried":false,
"car":null,
"house":null,
"comment":"這是一個注釋"
}ps:json是沒有//注釋的。
查看全部 -
?數(shù)據(jù)結(jié)構(gòu):Object、Array ?基本類型:string,number,true,false,null ?(1)Object ? {key:value,key:value...} ? key:string類型。 ? value:任何基本類型或數(shù)據(jù)結(jié)構(gòu)。 ? (2)Array ? [value,value...] ? value:任何基本類型或數(shù)據(jù)結(jié)構(gòu)。
比如:{"name":"李廣", "values":[1,2,45,"你好"] }
查看全部 -
json是一種與開發(fā)語言無關(guān)的,輕量級的數(shù)據(jù)格式,全稱:javascript object notation JSON的樣例: ?{ ?"name":"Json快速入門(Java版)", ?"author":"李廣", ?"content":["JSON基礎(chǔ)入門","常用JSON處理"], ?"time":{"value":30, ? ? ? ? ?"unit":"分鐘" } }
查看全部 -
JSON是數(shù)據(jù)傳輸格式。。。 JSON可以作為一種數(shù)據(jù)返回格式,也可以作為一種數(shù)據(jù)存儲格式。。。 ? 大多數(shù)API用JSON作為返回格式。。。 數(shù)據(jù)庫也會選JSON進(jìn)行數(shù)據(jù)存儲,JSON提供了一種對象序列化的方式。。。
查看全部 -
總結(jié)
查看全部 -
json數(shù)據(jù)對象
{
""name" : "王小二",
"age" : 25.2,
"birthday" : "90.01.01"
}
查看全部 -
JSON和GSON都是庫函數(shù)
查看全部 -
getJSONArray()是我要獲取JSON格式的數(shù)組
major是key 返回值就是JSONArray
查看全部 -
JSON數(shù)據(jù)結(jié)構(gòu)—Array
查看全部 -
JSON數(shù)據(jù)結(jié)構(gòu)—Object
查看全部 -
當(dāng)我們開發(fā)手機(jī)app,需要調(diào)用服務(wù)端api的時候。大多數(shù)api都使用json作為數(shù)據(jù)的返回格式
查看全部 -
2
查看全部 -
集合類演示
查看全部
舉報