Java String to Map toMap(String jsonStr)

Here you can find the source of toMap(String jsonStr)

Description

to Map

License

Apache License

Declaration

public static Map<String, String> toMap(String jsonStr) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.HashMap;

import java.util.Map;

public class Main {
    public static Map<String, String> toMap(String jsonStr) {
        Map<String, String> newMap = new HashMap<String, String>();
        jsonStr = jsonStr.replace("{", "").replace("}", "");
        String[] blocks = jsonStr.split(",");
        for (int i = 0; i < blocks.length; i++) {
            String block = blocks[i];
            int indexOfCarac = block.indexOf("=");
            if (indexOfCarac < 0) {
                continue;
            }/*from   w  w w.j a va 2 s  .  c o m*/
            String key = block.substring(0, indexOfCarac).trim();
            String value = block.substring(indexOfCarac + 1, block.length()).trim();
            newMap.put(key, value);
        }
        return newMap;
    }
}

Related

  1. StringToMap(String str)
  2. stringToMap(String str)
  3. stringToMap(String value)
  4. stringToMap(String[] strings)
  5. toMap(String componentName, String contextName)
  6. toMap(String parameters)
  7. toMap(String s)
  8. toMap(String s)
  9. toMap(String source)