JsonObject和JsonObject转化
1.可以直接将JsonObject对象赋给JsonObject对象
public static void main(String[] args)
{
String propertyPairs = "{\"id\":1,\"name\":\"nihh\"}";
JSONObject property = JSONObject.fromObject(propertyPairs);
Map<String, Object> propetyMap = property;
System.out.println(propetyMap.get("id"));
}
- 通过迭代器转化
String propertyPairs = "{\"id\":1,\"name\":\"nihh\"}";
JSONObject property = JSONObject.fromObject(propertyPairs);
HashMap<String, Object> data = new HashMap<String, Object>();
Iterator it = property.keys();
// 遍历jsonObject数据,添加到Map对象
while (it.hasNext())
{
String key = String.valueOf(it.next());
String value = (String) jsonObject.get(key);
data.put(key, value);
}
System.out.println(data);