2024-09-28 00:46:42
将一个String 形式的json转化成Map的Java程序如下:
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.json.JSONObject;
public class FFF {
public static void main(String[] args) {
String s="{\"a\":\"1\",\"b\":2,\"c\":\"2016-5\"}";
JSONObject jso=new JSONObject(s);
Map<String,Object> m=new HashMap<String,Object>();
Iterator it = jso.keys();
while (it.hasNext()) {
String key = (String) it.next();
Object value = jso.get(key);
m.put(key, value);
}
System.out.println(m.toString());
}
}
运行结果:
{a=1, b=2, c=2016-5}
2024-09-28 01:19:07