本文整理了Java中com.alibaba.fastjson.JSON.parse()
方法的一些代码示例,展示了JSON.parse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON.parse()
方法的具体详情如下:
包路径:com.alibaba.fastjson.JSON
类名称:JSON
方法名:parse
暂无
代码示例来源:origin: com.alibaba/fastjson
/**
*
* @since 1.2.38
*/
public static Object parse(String text, ParserConfig config) {
return parse(text, config, DEFAULT_PARSER_FEATURE);
}
代码示例来源:origin: apache/incubator-dubbo
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;
}
代码示例来源:origin: apache/incubator-dubbo
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;
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public Object readObject() throws IOException, ClassNotFoundException {
String json = readLine();
return JSON.parse(json);
}
代码示例来源:origin: hs-web/hsweb-framework
@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;
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public Object readObject() throws IOException, ClassNotFoundException {
String json = readLine();
return JSON.parse(json);
}
代码示例来源:origin: alibaba/canal
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;
}
代码示例来源:origin: alibaba/fastjson
/**
* @since 1.2.9
* @param json
* @param path
* @return
*/
public static Object read(String json, String path) {
return compile(path)
.eval(
JSON.parse(json)
);
}
代码示例来源:origin: com.alibaba/fastjson
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);
}
代码示例来源:origin: com.alibaba/fastjson
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);
}
代码示例来源:origin: Dreampie/Resty
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);
}
}
代码示例来源:origin: com.alibaba/fastjson
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);
}
代码示例来源:origin: com.alibaba/fastjson
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);
}
代码示例来源:origin: com.alibaba/fastjson
/**
* @since 1.2.9
* @param json
* @param path
* @return
*/
public static Object read(String json, String path) {
return compile(path)
.eval(
JSON.parse(json)
);
}
代码示例来源:origin: com.alibaba/fastjson
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);
}
}
代码示例来源:origin: TommyLemon/APIJSON
/**
* @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
代码示例来源:origin: TommyLemon/APIJSON
/**
* @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
代码示例来源:origin: TommyLemon/APIJSON
/**
* @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
代码示例来源:origin: TommyLemon/APIJSON
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;
}
代码示例来源:origin: alibaba/fastjson
propertyValue = JSON.parse(jsonStr);
内容来源于网络,如有侵权,请联系作者删除!