-
這是一個(gè)標(biāo)準(zhǔn)的json格式
查看全部 -
使用JSONArray來獲取數(shù)組
查看全部 -
json-表示數(shù)組
使用中括號來起始,并用逗號進(jìn)行分割
查看全部 -
數(shù)據(jù)結(jié)構(gòu)-object
查看全部 -
標(biāo)準(zhǔn)json數(shù)據(jù)標(biāo)識
基本類型:string,number,true,false,null
查看全部 -
json:輕量級的數(shù)據(jù)格式查看全部
-
json:輕量級的數(shù)據(jù)格式查看全部
-
從文件中讀取JSON
首先讀取文件
把文件轉(zhuǎn)化為String類型的
構(gòu)建JSONObject對象讀取相關(guān)的屬性
查看全部 -
使用javabean構(gòu)建JSON對象,好處:業(yè)務(wù)對象可以重用,
在一個(gè)類中創(chuàng)建JavaBean對象,
在其他類中調(diào)用直接初始化javabean對象使用。
好處就是可以重用javaBean對象
查看全部 -
構(gòu)建JSON對象主要通過2種方法:
JsonObject duixiangming=new JsonObject();
Map<String ,Object> duixingming=new Map<String Object>;
當(dāng)使用Map這種方法構(gòu)建對象時(shí),如果要輸出,則需要進(jìn)行轉(zhuǎn)化。
查看全部 -
JSON中沒有日期的格式,有String, ?false null等基本的數(shù)據(jù)類型。
想要表示日期,就要用字符串來表示
查看全部 -
谷歌的Gson強(qiáng)大之處可以正向生成反向解析
查看全部 -
判斷Json數(shù)據(jù)中是否有指定的信息 JSONObject jsonObject = new JSONObject(content); if (!jsonObject.isNull("name")) System.out.println("姓名:" + jsonObject.getString("name")); if (!jsonObject.isNull("age")) System.out.println("年齡:" + jsonObject.getDouble("age")); if (!jsonObject.isNull("birthday")) System.out.println("生日:" + jsonObject.getString("birthday")); if (!jsonObject.isNull("school")) System.out.println("學(xué)校:" + jsonObject.getString("school"));
查看全部 -
解析json: ?pom.xml里一個(gè)依賴 commons-io 從文件中間讀取json內(nèi)容 // 聲明這個(gè)文件 File file = new File(ReadJSONSample.class.getResource("/wangxiaoer.json").getFile()); //通過依賴 ?FileUtils ? String content = FileUtils.readFileToString(file); //通過 JSONObject 這個(gè)對象進(jìn)行處理 JSONObject jsonObject = new JSONObject(content);
如何解釋Json數(shù)據(jù) JSONObject json=new JSONObject(content); System.out.println("姓名:"+json.getString("name")); Sytem.out.println("年齡:"+json.getInt("age")); System.out.println("是否有車:"+json.getBoolean("car")); JSONArray array=json.getJSONArray("major"); for(int I=0;i<array.length();I++) { String s=(String)array.get(I); System.outprintln("專業(yè):"+(I+1)+m)); }
查看全部 -
使用Bean實(shí)現(xiàn)Json Bean Class: public class DaShen { ? private Stringname; ? private Stringschool; ? private boolean has_girlfriend; ? private double age; ? private Objectcar; ? private Objecthouse; ? private String[]major; ? private Stringcomment; ? private String birthday; } 實(shí)現(xiàn): ? private static void createJsonByBean() ? { ? ? ?DaShen terence=newDaShen(); ? ? ?terence.setAge(25.9); ? ? ?terence.setBirthday("1990-5-9"); ? ? ?terence.setSchool("HDU"); ? ? ?terence.setMajor(new String[]{"Computer","qiqiqiqi"}); ? ? ?terence.setHas_girlfriend(false); ? ? ?terence.setComment("sha,sha,sha,sha……"); ? ? ?terence.setCar(null); ? ? ?terence.setHouse(null); ? ? ?System.out.println(new JSONObject(terence)); ? }
查看全部
舉報(bào)