
- 如果我们需要实现一个配置管理的功能,那么为每个配置项目增加一个字段既复杂也不利于扩展,所以我们通常使用一个字符串来保存配置项目信息,这里介绍如何使用json的字符串解析来达到刚才说的目的。引入Json需要的类库:
- importorg.json.JSONException;
- importorg.json.JSONObject;
- 生成一个json对象(可以添加不同类型的数据):
- JSONObjectjsonObject=newJSONObject();jsonObject.put("a",1);
- jsonObject.put("b",1.1);
- jsonObject.put("c",1L);
- jsonObject.put("d","test");
- jsonObject.put("e",true);
- System.out.println(jsonObject);
- //{"d":"test","e":true,"b":1.1,"c":1,"a":1}
- JSONObjectjsonObject=newJSONObject();
- jsonObject.put("a",1);
- jsonObject.put("b",1.1);
- jsonObject.put("c",1L);
- jsonObject.put("d","test");
- jsonObject.put("e",true);
- System.out.println(jsonObject);
- //{"d":"test","e":true,"b":1.1,"c":1,"a":1}
- 解析一个json对象(可以解析不同类型的数据):
- jsonObject=getJSONObject("{d:test,e:true,b:1.1,c:1,a:1}");
- System.out.println(jsonObject);
- //{"d":"test","e":true,"b":1.1,"c":1,"a":1}
- System.out.println(jsonObject.getInt("a"));
- System.out.println(jsonObject.getDouble("b"));
- System.out.println(jsonObject.getLong("c"));
- System.out.println(jsonObject.getString("d"));
- System.out.println(jsonObject.getBoolean("e"));
- jsonObject=getJSONObject("{d:test,e:true,b:1.1,c:1,a:1}");
- System.out.println(jsonObject);
- //{"d":"test","e":true,"b":1.1,"c":1,"a":1}
- System.out.println(jsonObject.getInt("a"));
- System.out.println(jsonObject.getDouble("b"));
- System.out.println(jsonObject.getLong("c"));
- System.out.println(jsonObject.getString("d"));
- System.out.println(jsonObject.getBoolean("e"));
- getJSONObject(Stringstr)
- publicstaticJSONObjectgetJSONObject(Stringstr){
- if(str==null||str.trim().length()==0)
- returnnull;
- JSONObjectjsonObject=null;
- try{jsonObject=newJSONObject(str);}
- catch(JSONExceptione){
- e.printStackTrace(System.err);}
- returnjsonObject;
爱华网本文地址 » http://www.aihuau.com/a/25101016/316310.html
更多阅读
怎样理解换手率是什么意思? 1、 换手率是指个股日成交量与其流通盘的比值,它反映了个股的活跃程度,在实战操作之中,对量的研判是非常重要的,换手率是值得长期关注的指标。其原理和方法: 大家知道,热门股的重要特征是股价表现活跃、成交量

刷机是什么意思刷机就是给智能手机重装系统,进行系统安装的操作。就像是给自己的电脑从新装系统一样,刷机的目的在于提高整机运行性能.升级原来的系统,能够修正系统bug让手机运行得更加稳定.更换自己喜欢的版本.删除官方手机自带的一

今天我们来说一下,Macd金叉是什么意思,Kdj金叉是什么意思这俩个问题。首先大家要长得,股市技术面上看,是存在金叉和死叉二种概念的,金叉的出现一般意味着上涨,死叉的出现一般意味着下跌。但这里建议大家看金叉或者死叉时,不要只看日K线,还

安卓手机root是什么意思及root开启会怎么样?——简介ROOT是安卓手机最高的权限身份,就像计算机中拥有超级管理员的身份那样!很多厂家都为用户着想,很多用户新接触安卓手机,对手机系统非常不了解,所以设置了ROOT权限。如果你手机没有ROOT

4G网络是什么意思4G手机什么时候上市——简介4G网络是什么意思4G手机什么时候上市:中国第四代无线通信网络系统技术诞生了,而且是中国人的技术!国人该为之骄傲!第四代无线通信网络系统技术统称为4G网络,世界科研人员还在研发当中!也是未来