当前位置: 首页 > news >正文

微信网站模版已备案域名查询网

微信网站模版,已备案域名查询网,湘潭网站制作,郴州365网通过学习ajax然后接触了Json最后通过json接触到了JSONObject和Google的GSON#xff0c;下面来一起看看JSONObject和GSON吧。 先附上依赖 //JSONObject依赖dependencygroupIdnet.sf.json-lib/groupIdartifactIdjson-lib/artifactId下面来一起看看JSONObject和GSON吧。 先附上依赖 //JSONObject依赖dependencygroupIdnet.sf.json-lib/groupIdartifactIdjson-lib/artifactIdversion2.4/versionclassifierjdk15/classifier/dependency顺便附上junit的依赖 毕竟用junit测试的 dependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.10/version/dependency差点忘记了这是FileUtils文件操作工具类的依赖 dependencygroupIdcommons-io/groupIdartifactIdcommons-io/artifactIdversion2.0.1/version/dependencyemmm直接上案例吧 package test;import com.JSON.domain.User; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.junit.Test;import java.util.Date; import java.util.HashMap;public class JSONTEST {Testpublic void TestJSON(){/*** 通过原生生成json数据格式*/JSONObject jsonObjectnew JSONObject();jsonObject.put(name,李四);jsonObject.put(home,true);jsonObject.put(number,134.11);jsonObject.put(sex,男);System.out.println(jsonObject.toString());/***通过map来生成json数据格式*/HashMapString,Object mapnew HashMapString, Object();map.put(name,张三);map.put(home,true);map.put(技能,new String[]{json,java,python});System.out.println(JSONObject.fromObject(map).toString());JSONArray mapJsonJSONArray.fromObject(map); //数组格式mapJson.add(1, new String[]{dajhdka,dagdhag}); // mapJson.add(2,是否有女朋友,);System.out.println(mapJson.toString());/*** 通过实体类生成json数据格式*/User usernew User(小红,女,1550.2,false);JSONObject jsonObject1JSONObject.fromObject(user);System.out.println(jsonObject1);}Testpublic void TestGSON(){GsonBuilder gsonBuildernew GsonBuilder(); //设定格式的User usernew User(小红,女,1550.2,false,new Date());/*** String toJson(object) 返回值是String 将对象转换成json格式*/gsonBuilder.setDateFormat(yyyy-MM-dd HH:mm:ss); //设定date属性 有误json本身没有date类型Gson gsongsonBuilder.create();String Gjsongson.toJson(user);System.out.println(Gjson);/*** 将JSON格式转换成实体类* 不清楚为什么我用了 复用功能的话 json格式转换成的实体类就没有值了 就是无法定位到*/String content{\name\:\小红\,\sex\:\女\,\number\:1550.2,\home\:false,\birthday\:\2020-02-17\};User user1gson.fromJson(content,User.class);System.out.println(user1);} }JSONobject的案例 GSON的案例 实体类 package com.JSON.domain;import com.google.gson.annotations.SerializedName;import java.util.Date;public class User {private String name; // SerializedName() //SEXGson提供了字段复用功能 SerializedName 大概就是别名的意思吧应该不确定private String sex;private double number;private boolean home;private Date birthday;public Date getBirthday() {return birthday;}Overridepublic String toString() {return User{ name name \ , sex sex \ , number number , home home , birthday birthday };}public void setBirthday(Date birthday) {this.birthday birthday;}public User(String name, String sex, double number, boolean home,Date birthday){this.namename;this.sexsex;this.numbernumber;this.homehome;this.birthdaybirthday;}public User(String name, String sex, double number, boolean home){this.namename;this.sexsex;this.numbernumber;this.homehome;}public String getName() {return name;}public void setName(String name) {this.name name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex sex;}public double getNumber() {return number;}public void setNumber(double number) {this.number number;}public boolean isHome() {return home;}public void setHome(boolean home) {this.home home;} } 上面都是一些基础的语法下面这个案例是JSONObject读取外部json文件 首先是外部文件的位置 为什么放这里呢 因为.class的获取的路径就是这边的 所以我把JSON.json放这 JSON.json {name: 小红,sex: 女,number: 1667.2,home: false}package test;import net.sf.json.JSONObject; import org.apache.commons.io.FileUtils; import org.junit.Test;import java.io.File; import java.io.IOException;public class JSONTextParsing {Testpublic void JSONTest() throws IOException {//获取json文档/*** class.getResource() 会获取target底下的class的 上一级的包* 这里是 file:/D:/IdeaProjects/Web/JSON_GSON__TEST/target/test-classes/test/*/// System.out.println(JSONTextParsing.class.getResource());File filenew File(JSONTextParsing.class.getResource(JSON.json).getFile());//找到该文件/*** 使用阿帕奇的jar包 commons-io* 获取文本信息 String类型 readFileToString 并保留格式*/String contentFileUtils.readFileToString(file);JSONObject jsonObjectJSONObject.fromObject(content);System.out.println(jsonObject);}}其实还有很多方法没用到emmm 反正到时候用到了再说吧… …
http://www.yutouwan.com/news/229147/

相关文章:

  • 网站开发教程公司潍坊住房和城乡建设局招标网站
  • 怎么用网站做远控找网站推广
  • 请人做网站学做粤菜的网站有哪些
  • 中国最知名的网站建设公司产品设计考研
  • 做外贸面料哪个网站可以接单网站安全检测怎么关掉
  • 网站建设工作总结6品牌注册查询官网入口
  • 海南七星彩网站开发淘宝客网站需要备案
  • 东营网站建设费用网站开发综合设计报告
  • 楚雄网站建设公司一站式免费建站平台
  • 网站建设商虎小程序蚌埠做网站公司
  • 百度seo新站优化制作一个购物网站
  • 北海教网站建设个人做视频网站烧钱
  • 重庆网站建设公司价格珠海网页模板建站
  • 商业网站开发设计报告南宁网站搜索引擎优化
  • 郑州专业网站制作服务报价二手车网站开发多少钱
  • asp提高网站安全性的措施教育机构网站源码
  • 三网一体网站建设网络传媒公司怎么注册
  • iis7 asp网站运行缓慢达州达县网站建设
  • 教做潮男的网站岳阳seo优化
  • 做网站运营的女生多吗最简单的网站代码
  • 茶叶门户网站建立如何查看网站流量
  • 龙泉市旅游门户网站建设引流效果最好的平台
  • 外贸专业网站制作做网站推广被骗
  • 网站建设一年600做代理需要自己的网站吗
  • 镇江建工建设集团网站12306网站建设费用
  • 搭建个人网站定制开发app软件
  • 现在用什么软件做网站公司logo在线设计生成器
  • 萧山做网站的公司做网站准备内容
  • 专业的制作网站开发公司优化大师会员兑换码
  • 扬州市做网站做dm素材网站