一 概述
有时候我们需要对对象字符长进行解析然后获取其中的某个字段的值。
二 实例
解析Map<String,Object>对象字符串中value中的某个值
String json = "{\"17db7ff07da\":{\"productImg\":\"https://cdn.91jiekuan.com/FgKrNyt_otG8HTyzDVCVhcBG4VMq\",\"x\":161,\"y\":42,\"w\":430,\"h\":659,\"fixedModel\":\"normal\",\"jiLiPic\":\"\",\"dpi\":300,\"actualW\":170,\"actualH\":260,\"expectW\":2008,\"expectH\":3071}}";
Map map = JSONObject.parseObject(json, Map.class);
JSONObject jsonObject = JSONObject.parseObject(json);
Integer expectH = (Integer) JSONObject.parseObject(jsonObject.get(map.keySet().toArray()[0]).toString()).get("expectH");
Integer expectW = (Integer) JSONObject.parseObject(jsonObject.get(map.keySet().toArray()[0]).toString()).get("expectW");
System.out.println(expectH + "--" + expectW);
结果:
简单实例仅供参考,哈哈!