获取json路径下的某个元素(如果路径不存在返回null值) @param jsonPath 例如"rpg/man/hp",rpg和man为jsonObject @return
(String jsonPath)
| 54 | * @return |
| 55 | */ |
| 56 | public Object get(String jsonPath) { |
| 57 | jsonPath = jsonPath.replaceAll("\\.", "/"); |
| 58 | String[] paths = jsonPath.split("/"); |
| 59 | Object o = null; |
| 60 | JSONObject object = jsonObj; |
| 61 | try { |
| 62 | for (String name : paths) { |
| 63 | o = object.get(name); |
| 64 | if (o instanceof JSONObject) |
| 65 | object = (JSONObject) o; |
| 66 | } |
| 67 | } catch (JSONException e) { |
| 68 | e.printStackTrace(); |
| 69 | } |
| 70 | return o; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * 获取json路径下的某个元素(如果路径不存在返回null值,并自动创建路径) |
no test coverage detected