Entering Colorful for the first time
If the guys don’t have the Colorful framework installed - you can read my previous article - native implementation:
Click ->
click me to view the installation of Colorful1.0
code part
If you have done all this, excellent you can start!
Meet the JTO Collection
To put it bluntly, JTO is a mapping module. As long as you know
a collection like HashMap, the JTO in Colorful
has the same API name as Colorful - the same key value can also exist - it is based on the TaskList collection design of the Colorful1.0 framework of
SeeAll is just for viewing convenience!
JTO to JSON
JSON is an internal module of JTO - here comes the code!
JTO<String,Object> jto=new JTO<>();
jto.put("name","value");
jto.put("name","value2");
//这个只是为了方便查看JTO内部
jto.SeeAll();
//转换成JSON了
console.info(jto.toJSON());
Map to JSON
Of course, although JTO can be converted to any mapping set - because the mapping principles are the same
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));
You can add unlimited branches
HashMap to JTO
Let's see how HashMap turns - in fact, just add a
_Hash at the end
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));
JSON to JTO
Let's take a look at how we can convert the json to JTO! Use the JTO static conversion module to complete
String JSON="{'name':'123','other':'{other1=ABC}'}";
JTO<String,Object> json=JTO.JSONParse(JSON);
//查看内部信息
json.SeeAll();
JSON to Map
Of course, you can also transfer to 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 to HashMap
The above code 3: In fact, after the map is turned, I guess that HashMap can also be used, which is obvious
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"));
end
The JSON module conversion of colorful1.0 is complete
Let's learn together with Mr. Atomic!.