为了账号安全,请及时绑定邮箱和手机立即绑定
慕课网数字资源数据库体验端
JSON快速入门(Java版)_学习笔记_慕课网
为了账号安全,请及时绑定邮箱和手机立即绑定

JSON快速入门(Java版)

李广
难度初级
时长 1小时12分
  • package bean; public class Diaosi { private String name; private String school; private boolean has_girlfriend; private double age; private Object car; private Object house; private String[] major; private String comment; private String birthday; }
    查看全部
  • private static void createJsonByBean() { Diaosi wangxiaoer = new Diaosi(); wangxiaoer.setName("王小二"); wangxiaoer.setAge(25.2); wangxiaoer.setBirthday("1990-01-01"); wangxiaoer.setSchool("蓝翔"); wangxiaoer.setMajor(new String[] { "理发", "挖掘机" }); wangxiaoer.setHas_girlfriend(false); wangxiaoer.setCar(null); wangxiaoer.setHouse(null); wangxiaoer.setComment("这是一个注释"); System.out.println(new JSONObject(wangxiaoer)); }
    查看全部
  • 有3种方式,创建json对象, 1、使用JSONObject对象put方法来构建; 2、使用HashMap及其子类如treeMap的put方法来构建; 3、使用JavaBean来构建JSONObject对象。 出现"major":[{"bytes":[{},{},{},{},{},{}],"empty":false}的可以换个org.json的新版本,亲测可用。 Maven依赖: <dependencies> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20160810</version> </dependency>
    查看全部
  • 使用Map实现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", "蓝翔"); wangxiaoer.put("major", new String[] { "理发", "挖掘机" }); 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实现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", "蓝翔"); wangxiaoer.put("major", new String[] { "理发", "挖掘机" }); 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(); } } }
    查看全部
    4 采集 收起 来源:JSON使用

    2018-03-22

  • { "name": "王小二", "age": 25.2, "birthday": "1990-01-01", "school": "蓝翔", "major": [ "理发", "挖掘机" ], "has_girlfriend": false, "car": null, "house": null, "comment": "这是一个注释" }
    查看全部
    0 采集 收起 来源:JSON数据演示

    2018-03-22

  • 数据结构:Object、Array 基本类型:string,number,true,false,null (1)Object {key:value,key:value...} key:string类型。 value:任何基本类型或数据结构。 (2)Array [value,value...] value:任何基本类型或数据结构。
    查看全部
    0 采集 收起 来源:数据类型表示

    2017-08-17

  • json是一种与开发语言无关的,轻量级的数据格式,全称:javascript object notation JSON的样例: { "name":"Json快速入门(Java版)", "author":"李广", "content":["JSON基础入门","常用JSON处理"], "time":{"value":30, "unit":"分钟" } }
    查看全部
    0 采集 收起 来源:什么是JSON

    2018-03-22

  • JSON是当前行业内使用最为广泛的一种数据传输格式,是开发人员必备技能之一 选择JSON 可以做为一种数据返回格式,也可以做为一种数据存数格式 大多数API 用json作为返回格式 数据库 也会用json格式进行数据存储 json提供了一种对象序列化的方式
    查看全部
    0 采集 收起 来源:JSON课程介绍

    2017-08-17

  • 直接new一个jsond对象,它的构造函数中有直接传递map集合的参数
    查看全部
  • json的数据表示
    查看全部
    0 采集 收起 来源:数据类型表示

    2017-08-16

  • 这是什么
    查看全部
    0 采集 收起 来源:JSON课程介绍

    2017-08-15

  • Json-java 库 是使用反射类的Method获取信息来构建json的;而Gson是使用反射类的Field信息来构建json的。
    查看全部
    0 采集 收起 来源:总结

    2017-08-14

  • Json解析 public class ReadJsonSample { //反向解析为一个json public static void main(String[] args)throws Exception{ File file=new File(ReadJsonSample.class.getResource("/data/terence.json").getFile()); String content=FileUtils.readFileToString(file); JSONObject jsonObject=new JSONObject(content); if(!jsonObject.isNull("name")) { System.out.println("姓名:"+jsonObject.getString("name")); } System.out.println("年龄:"+jsonObject.getDouble("age")); } }
    查看全部
    0 采集 收起 来源:从文件读取JSON

    2018-03-22

  • 使用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)); }
    查看全部

举报

0/150
提交
取消
课程须知
学习本门课程前,需要对Java基础知识有所了解呦!
老师告诉你能学到什么?
1、能够使用JSON进行数据的生成和解析 2、能够使用GSON进行数据的生存和解析
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!