Json的理解
来源:互联网 发布:mysql if else 多条件 编辑:程序博客网 时间:2024/06/05 13:23
今天用到了Json发现还是要重写遍代码,才能记起来
class TestJson {public static void main(String[] args) {TestJson te = new TestJson();te.jsonS();}public static String jsonS(){JSONObject js = new JSONObject();List<Phone> list = new ArrayList<>();list.add(new Phone("MIUI", 1000.99));list.add(new Phone("Apple", 7000.99));HashMap<String, List<Phone>> map = new LinkedHashMap<>();map.put("Phone", list);//方法一 map的key为变量 list为数组内JSONObject obj = JSONObject.fromObject(map);System.out.println(obj.toString());//方法2 可以添加变量 map 的key为数组内的keyjs.put("Gzh", list);js.put("GuoF",map);System.out.println(js);//获取值 JSON结构 {变量:[{key:value,key:value},{key:value},{key:value}]} //中括号内是数组//JSONObject jsonObj = JSONObject.fromObject(obj.toString());//System.out.println(jsonObj);String array =obj.getString("Phone");System.out.println(array);JSONArray array2 =obj.getJSONArray("Phone");System.out.println("Phone:"+array2.getString(0));System.out.println("Phone:"+array2.getString(1));return obj.toString();//String phone = js.getObject(1);}}
0 0
- json的理解
- JSON的理解
- JSON的理解使用
- 关于JSON的理解
- json的理解
- Json的理解
- 对json的理解
- JSON的理解
- JSON的理解
- 关于json的理解
- json的初步理解
- JSON的理解
- 对json的理解
- 对于json的理解
- 对json的理解
- json字符串的理解
- JSON的初步理解
- 有关json的一些理解
- POJ2406(KMP)
- 自学PHP-9.18
- 不错的css3的网站
- 爱的律法
- AD10 敷铜(画完PCB后改线与敷铜冲突)
- Json的理解
- 面向对象的设计原则
- pPOWERSHELL EMPIRE + CVE-2016-0189 = PROFIT
- VS2010下生成dll的方法
- HashMap类和Hashtable类概述
- 实验二 Intent 简单标准体重计算器
- SPI总线协议及SPI时序图详解
- 使用map时容易犯错的细节
- hdu5887 Herbs Gathering 搜索01背包