zoukankan      html  css  js  c++  java
  • Json、List、Map、String 互转

    import net.sf.json.JSONArray;
    import net.sf.json.JSONObject;

    public static void main(String[] args) {
    List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("a", "b");
    map.put("b", "c");
    list.add(map);
    String arrStr = JSONArray.fromObject(list).toString();//list转String
    String objStr = JSONObject.fromObject(map).toString();//map转String
    System.out.println(arrStr);//[{"b":"c","a":"b"}]
    System.out.println(objStr);//{"b":"c","a":"b"}
    JSONArray arr = JSONArray.fromObject(arrStr);
    List<Map<String, Object>> list1 = JSONArray.fromObject(arrStr);
    JSONObject obj = JSONObject.fromObject(objStr);
    Map<String, Object> map1 = JSONObject.fromObject(objStr);
    }

  • 相关阅读:
    UVa 107 The Cat in the Hat
    UVa 591 Box of Bricks
    UVa 253 Cube painting
    UVa 10161 Ant on a Chessboard
    UVa 401 Palindromes
    UVa 465 Overflow
    我不知道
    消防局的设立
    某CF的D
    保安站岗
  • 原文地址:https://www.cnblogs.com/chai-blogs/p/8126185.html
Copyright © 2011-2022 走看看