I have a problem in my work today , somewhat Map < String, Object > Type of data I need to put redis in , But from redis Out of it is String type
Need to transfer Map. Think about it Just remember Map.toString() In this way, the Map Convert to String. I don't remember how String turn map
Tried it, too Map There seems to be no self-contained method String turn Map of
I found a way on the Internet :
public static Map<String, Object> getValue(String param) { Map<String,
Object> map = new HashMap<>(); String str = ""; String key = ""; Object value =
""; char[] charList = param.toCharArray(); boolean valueBegin = false; for (int
i = 0; i < charList.length; i++) { char c = charList[i]; if (c == '{') { if
(valueBegin == true) { value = getValue(param.substring(i, param.length())); i
= param.indexOf('}', i) + 1; map.put(key, value); } } else if (c == '=') {
valueBegin = true; key = str; str = ""; } else if (c == ',') { valueBegin =
false; value = str; str = ""; map.put(key, value); } else if (c == '}') { if
(str != "") { value = str; } map.put(key, value); return map; } else if (c != '
') { str += c; } } return map; }
Then I wrote a method Simple test :
public static void main(String[] args) { Map<String, Object> map = new
HashMap<String, Object>(); map.put("aaa", 11); map.put("bbb", 22);
map.put("ccc", 33); map.put("ddd", 44); String string = map.toString();
System.out.println("map turn String"+string); // Map<String, Object> stringToMap =
getStringToMap(string); Map<String, Object> stringToMap = getValue(string);
for(Object a : stringToMap.keySet()) {
System.out.println(stringToMap.get(a).toString()); } }
Operation results :

It should be noted that value In value No comma (,)

Technology
©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?