public static Object getValueByKey(String json, String key) throws Exception
{
Map<String, Object> maps = new ObjectMapper().readValue(json, Map.class);
Set<String> keys = maps.keySet();
for (String k : keys)
{
if (k.equals(key))
{
return maps.get(k);
}
}
return null;
}
public static void main(String[] args) throws Exception
{
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("type", "1");
map.put("message", "该运单号不存在。");
map.put("success",false);
String result = JSON.json(map);
System.out.println(result);
Object object = getValueByKey(result, "success");
boolean param = Boolean.parseBoolean(object.toString());
System.out.println(param);
}
{
Map<String, Object> maps = new ObjectMapper().readValue(json, Map.class);
Set<String> keys = maps.keySet();
for (String k : keys)
{
if (k.equals(key))
{
return maps.get(k);
}
}
return null;
}
public static void main(String[] args) throws Exception
{
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("type", "1");
map.put("message", "该运单号不存在。");
map.put("success",false);
String result = JSON.json(map);
System.out.println(result);
Object object = getValueByKey(result, "success");
boolean param = Boolean.parseBoolean(object.toString());
System.out.println(param);
}