初入Colorful
我们需要安装Colorful基本框架-不需要任何下载额外Colorful插件库:
点击->
点我查看Colorful1.0安装
代码部分
如果你已经做好了这一切,优秀的你就可以开始了!
JTO集合
JTO是Colorful基础框架中的一个实现了Map的集合,提供了丰富的API更加方便操作(举例子)
JTO转JSON
JTO<String,Integer> C= JTO.LAX_Huffman("[王五=3,小米=2,二六=1]");
C.put("JSON",5);
//正序
C.sort(true);
//查看
C.SeeAll();
//彩色输出模块-单层JSON
console.info(C.toJSON());
Map 转 JSON
实际上也是Map的继承类
//自动向上转为MAP
Map<String,Object> C1= JTO.JSONInlay(JTO.LAX_String("[A=1SA,B=SCQ,X=SSQ]"));
//自动向上转为MAP
Map<String,Object> C= JTO.JSONInlay(JTO.LAX_Huffman("[王五=3,小米=2,二六=1]"));
C.put("A",C1);
//转JSON
console.info(JTO.JSON_Stringify(C));
无限添加分支
HashMap转JTO
Map<String,Object> branch=new HashMap<>();
branch.put("other1","ABC");
//分支↗
Map<String, Object> map=new HashMap<>();
map.put("name","123");
//可以无限添加分支
map.put("other",branch);
//输出
console.info(JTO.Map_toJSON(map));
HashMap转JSON
HashMap<String,Object> C1= new HashMap<>();
C1.put("C","12");
C1.put("C2","12");
C1.put("C3","12");
C1.put("C4","12");
HashMap<String,Object> C= new HashMap<>();
C.put("A",C1);
C.put("B",C1);
//转JSON
console.info(JTO.JSON_Stringify(C));
![](https://img-blog.csdnimg.cn/311d5633040a47529f42f5c37b8d8a2b.png)
JSON转JTO
来看看我们使用刚刚的json转成JTO吧!使用JTO静态转换模块完成
String JSON="{'name':'123','other':'{other1=ABC}'}";
JTO<String,Object> json=JTO.JSONParse(JSON);
//查看内部信息
json.SeeAll();
JSON转Map
当然也可以转Map
String JSON="{'name':'123','other':'{other1=ABC}'}";
Map<String,Object> json=JTO.JSONParser_Map(JSON);
//查看内部信息
console.info(json);
//获取单个的other1中的值
console.info(((Map)json.get("other")).get("other1"));
JSON转HashMap
上代码3:其实Map那个转了之后,就猜到HashMap也可以,这个很明显
String JSON="{'name':'123','other':'{other1=ABC}'}";
HashMap<String,Object> json=JTO.JSONParser_Hash(JSON);
//查看内部信息
console.info(json);
//获取单个的other1中的值
console.info(((HashMap)json.get("other")).get("other1"));
完结
colorful1.1的JSON模块转换就完结了