-
这是一个标准的json格式
查看全部 -
使用JSONArray来获取数组
查看全部 -
json-表示数组
使用中括号来起始,并用逗号进行分割
查看全部 -
数据结构-object
查看全部 -
标准json数据标识
基本类型:string,number,true,false,null
查看全部 -
json:轻量级的数据格式查看全部
-
json:轻量级的数据格式查看全部
-
从文件中读取JSON
首先读取文件
把文件转化为String类型的
构建JSONObject对象读取相关的属性
查看全部 -
使用javabean构建JSON对象,好处:业务对象可以重用,
在一个类中创建JavaBean对象,
在其他类中调用直接初始化javabean对象使用。
好处就是可以重用javaBean对象
查看全部 -
构建JSON对象主要通过2种方法:
JsonObject duixiangming=new JsonObject();
Map<String ,Object> duixingming=new Map<String Object>;
当使用Map这种方法构建对象时,如果要输出,则需要进行转化。
查看全部 -
JSON中没有日期的格式,有String, false null等基本的数据类型。
想要表示日期,就要用字符串来表示
查看全部 -
谷歌的Gson强大之处可以正向生成反向解析
查看全部 -
判断Json数据中是否有指定的信息 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("学校:" + jsonObject.getString("school"));
查看全部 -
解析json: pom.xml里一个依赖 commons-io 从文件中间读取json内容 // 声明这个文件 File file = new File(ReadJSONSample.class.getResource("/wangxiaoer.json").getFile()); //通过依赖 FileUtils String content = FileUtils.readFileToString(file); //通过 JSONObject 这个对象进行处理 JSONObject jsonObject = new JSONObject(content);
如何解释Json数据 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("专业:"+(I+1)+m)); }
查看全部 -
使用Bean实现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; } 实现: 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)); }
查看全部
举报