/** * * @since 1.2.38 */ public static Object parse(String text, ParserConfig config) { return parse(text, config, DEFAULT_PARSER_FEATURE); }
public static Object parseMockValue(String mock, Type[] returnTypes) throws Exception { Object value = null; if ("empty".equals(mock)) { value = ReflectUtils.getEmptyObject(returnTypes != null && returnTypes.length > 0 ? (Class<?>) returnTypes[0] : null); } else if ("null".equals(mock)) { value = null; } else if ("true".equals(mock)) { value = true; } else if ("false".equals(mock)) { value = false; } else if (mock.length() >= 2 && (mock.startsWith("\"") && mock.endsWith("\"") || mock.startsWith("\'") && mock.endsWith("\'"))) { value = mock.subSequence(1, mock.length() - 1); } else if (returnTypes != null && returnTypes.length > 0 && returnTypes[0] == String.class) { value = mock; } else if (StringUtils.isNumeric(mock)) { value = JSON.parse(mock); } else if (mock.startsWith("{")) { value = JSON.parseObject(mock, Map.class); } else if (mock.startsWith("[")) { value = JSON.parseObject(mock, List.class); } else { value = mock; } if (ArrayUtils.isNotEmpty(returnTypes)) { value = PojoUtils.realize(value, (Class<?>) returnTypes[0], returnTypes.length > 1 ? returnTypes[1] : null); } return value; }
public static Object parseMockValue(String mock, Type[] returnTypes) throws Exception { Object value = null; if ("empty".equals(mock)) { value = ReflectUtils.getEmptyObject(returnTypes != null && returnTypes.length > 0 ? (Class<?>) returnTypes[0] : null); } else if ("null".equals(mock)) { value = null; } else if ("true".equals(mock)) { value = true; } else if ("false".equals(mock)) { value = false; } else if (mock.length() >= 2 && (mock.startsWith("\"") && mock.endsWith("\"") || mock.startsWith("\'") && mock.endsWith("\'"))) { value = mock.subSequence(1, mock.length() - 1); } else if (returnTypes != null && returnTypes.length > 0 && returnTypes[0] == String.class) { value = mock; } else if (StringUtils.isNumeric(mock)) { value = JSON.parse(mock); } else if (mock.startsWith("{")) { value = JSON.parseObject(mock, Map.class); } else if (mock.startsWith("[")) { value = JSON.parseObject(mock, List.class); } else { value = mock; } if (ArrayUtils.isNotEmpty(returnTypes)) { value = PojoUtils.realize(value, (Class<?>) returnTypes[0], returnTypes.length > 1 ? returnTypes[1] : null); } return value; }
@Override public Object readObject() throws IOException, ClassNotFoundException { String json = readLine(); return JSON.parse(json); }
@GetMapping(value = "/{modelId}/json") @Authorize(action = Permission.ACTION_GET) public Object getEditorJson(@PathVariable String modelId) { JSONObject modelNode; Model model = repositoryService.getModel(modelId); if (model == null) throw new NullPointerException("模型不存在"); if (StringUtils.isNotEmpty(model.getMetaInfo())) { modelNode = JSON.parseObject(model.getMetaInfo()); } else { modelNode = new JSONObject(); modelNode.put(MODEL_NAME, model.getName()); } modelNode.put(MODEL_ID, model.getId()); modelNode.put("model", JSON.parse(new String(repositoryService.getModelEditorSource(model.getId())))); return modelNode; }
@Override public Object readObject() throws IOException, ClassNotFoundException { String json = readLine(); return JSON.parse(json); }
public static Object convertToEsObj(Object val, String fieldInfo) { if (val == null) { return null; } if (fieldInfo.startsWith("array:")) { String separator = fieldInfo.substring("array:".length()).trim(); String[] values = val.toString().split(separator); return Arrays.asList(values); } else if (fieldInfo.startsWith("object")) { return JSON.parse(val.toString()); } return null; }
/** * @since 1.2.9 * @param json * @param path * @return */ public static Object read(String json, String path) { return compile(path) .eval( JSON.parse(json) ); }
public static Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, Feature... features) { if (input == null || input.length == 0) { return null; } int featureValues = DEFAULT_PARSER_FEATURE; for (Feature feature : features) { featureValues = Feature.config(featureValues, feature, true); } return parse(input, off, len, charsetDecoder, featureValues); }
public static Object parse(String text, Feature... features) { int featureValues = DEFAULT_PARSER_FEATURE; for (Feature feature : features) { featureValues = Feature.config(featureValues, feature, true); } return parse(text, featureValues); }
public static <T> T toObject(String json) { try { return (T) JSON.parse(json); } catch (JSONException e) { throw new JsonException("Could not cast \"" + json + "\" to " + JSONObject.class.getName(), e); } }
public static Object parse(byte[] input, Feature... features) { char[] chars = allocateChars(input.length); int len = IOUtils.decodeUTF8(input, 0, input.length, chars); if (len < 0) { return null; } return parse(new String(chars, 0, len), features); }
public JSONArray getJSONArray(String key) { Object value = map.get(key); if (value instanceof JSONArray) { return (JSONArray) value; } if (value instanceof List) { return new JSONArray((List) value); } if (value instanceof String) { return (JSONArray) JSON.parse((String) value); } return (JSONArray) toJSON(value); }
/** * @since 1.2.9 * @param json * @param path * @return */ public static Object read(String json, String path) { return compile(path) .eval( JSON.parse(json) ); }
public static JSONObject parseObject(String text) { Object obj = parse(text); if (obj instanceof JSONObject) { return (JSONObject) obj; } try { return (JSONObject) JSON.toJSON(obj); } catch (RuntimeException e) { throw new JSONException("can not cast to JSONObject.", e); } }
/** * @param json * @return */ public static Object parse(Object obj) { int features = com.alibaba.fastjson.JSON.DEFAULT_PARSER_FEATURE; features |= Feature.OrderedField.getMask(); try { return com.alibaba.fastjson.JSON.parse(obj instanceof String ? (String) obj : toJSONString(obj), features); } catch (Exception e) { Log.i(TAG, "parse catch \n" + e.getMessage()); } return null; } /**obj转JSONObject
/** * @param json * @return */ public static Object parse(Object obj) { int features = com.alibaba.fastjson.JSON.DEFAULT_PARSER_FEATURE; features |= Feature.OrderedField.getMask(); try { return com.alibaba.fastjson.JSON.parse(obj instanceof String ? (String) obj : toJSONString(obj), features); } catch (Exception e) { Log.i(TAG, "parse catch \n" + e.getMessage()); } return null; } /**obj转JSONObject
/** * @param json * @return */ public static Object parse(Object obj) { int features = com.alibaba.fastjson.JSON.DEFAULT_PARSER_FEATURE; features |= Feature.OrderedField.getMask(); try { return com.alibaba.fastjson.JSON.parse(obj instanceof String ? (String) obj : toJSONString(obj), features); } catch (Exception e) { Log.i(TAG, "parse catch \n" + e.getMessage()); } return null; } /**obj转JSONObject
protected Object getValue(@NotNull SQLConfig config, @NotNull ResultSet rs, @NotNull ResultSetMetaData rsmd , final int tablePosition, @NotNull JSONObject table, final int columnIndex, Map<String, JSONObject> childMap) throws Exception { Object value = rs.getObject(columnIndex); // Log.d(TAG, "name:" + rsmd.getColumnName(i)); // Log.d(TAG, "lable:" + rsmd.getColumnLabel(i)); // Log.d(TAG, "type:" + rsmd.getColumnType(i)); // Log.d(TAG, "typeName:" + rsmd.getColumnTypeName(i)); // Log.i(TAG, "select while (rs.next()) { >> for (int i = 0; i < length; i++) {" // + "\n >>> value = " + value); //数据库查出来的null和empty值都有意义,去掉会导致 Moment:{ @column:"content" } 部分无结果及中断数组查询! if (value instanceof Timestamp) { value = ((Timestamp) value).toString(); } else if (value instanceof String && isJSONType(rsmd, columnIndex)) { //json String value = JSON.parse((String) value); } return value; }
propertyValue = JSON.parse(jsonStr);