本文整理了Java中com.alibaba.fastjson.JSON
类的一些代码示例,展示了JSON
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON
类的具体详情如下:
包路径:com.alibaba.fastjson.JSON
类名称:JSON
暂无
代码示例来源:origin: alibaba/fastjson
public String toString() {
return JSON.toJSONString(this);
}
}
代码示例来源:origin: alibaba/fastjson
public String[] decode(String content) throws IOException {
return JSON.parseObject(content, String[].class);
}
代码示例来源:origin: liyiorg/weixin-popular
@Override
public List<PromotionDetail> unmarshal(String v) throws Exception {
String a = JSON.parseObject(v).getString("promotion_detail");
return JSON.parseArray(a, PromotionDetail.class);
}
代码示例来源: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: alibaba/nacos
@NeedAuth
@RequestMapping("/beat")
public JSONObject beat(HttpServletRequest request, HttpServletResponse response) throws Exception {
String entity = new String(IoUtils.tryDecompress(request.getInputStream()), "UTF-8");
String value = Arrays.asList(entity).toArray(new String[1])[0];
value = URLDecoder.decode(value, "UTF-8");
JSONObject json = JSON.parseObject(value);
JSONObject beat = JSON.parseObject(json.getString("beat"));
RaftPeer peer = RaftCore.HeartBeat.receivedBeat(beat);
return JSON.parseObject(JSON.toJSONString(peer));
}
代码示例来源:origin: alibaba/nacos
public static void onPublish(JSONObject json, boolean increaseTerm) throws Exception {
Datum datum = JSON.parseObject(json.getString("datum"), Datum.class);
RaftPeer source = JSON.parseObject(json.getString("source"), RaftPeer.class);
onPublish(datum, source, increaseTerm);
}
代码示例来源:origin: alibaba/nacos
@Override
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONObject jsonObj = (JSONObject) parser.parse();
String checkType = jsonObj.getString("type");
if (StringUtils.equals(checkType, AbstractHealthChecker.Http.TYPE)) {
return (T) JSON.parseObject(jsonObj.toJSONString(), AbstractHealthChecker.Http.class);
}
if (StringUtils.equals(checkType, AbstractHealthChecker.Tcp.TYPE)) {
return (T) JSON.parseObject(jsonObj.toJSONString(), AbstractHealthChecker.Tcp.class);
}
if (StringUtils.equals(checkType, AbstractHealthChecker.Mysql.TYPE)) {
return (T) JSON.parseObject(jsonObj.toJSONString(), AbstractHealthChecker.Mysql.class);
}
return null;
}
代码示例来源:origin: alibaba/nacos
public long sendBeat(BeatInfo beatInfo) {
try {
LogUtils.LOG.info("BEAT", "{} sending beat to server: {}", namespaceId, beatInfo.toString());
Map<String, String> params = new HashMap<String, String>(4);
params.put("beat", JSON.toJSONString(beatInfo));
params.put(Constants.REQUEST_PARAM_NAMESPACE_ID, namespaceId);
params.put("serviceName", beatInfo.getServiceName());
String result = reqAPI(UtilAndComs.NACOS_URL_BASE + "/instance/beat", params, HttpMethod.PUT);
JSONObject jsonObject = JSON.parseObject(result);
if (jsonObject != null) {
return jsonObject.getLong("clientBeatInterval");
}
} catch (Exception e) {
LogUtils.LOG.error("CLIENT-BEAT", "failed to send beat: " + JSON.toJSONString(beatInfo), e);
}
return 0L;
}
代码示例来源: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: alibaba/nacos
private Cluster getClusterFromJson(String json) {
JSONObject object = JSON.parseObject(json);
String type = object.getJSONObject("healthChecker").getString("type");
AbstractHealthChecker abstractHealthCheckConfig;
if (type.equals(HealthCheckType.HTTP.name())) {
abstractHealthCheckConfig = JSON.parseObject(object.getString("healthChecker"), AbstractHealthChecker.Http.class);
} else if (type.equals(HealthCheckType.TCP.name())) {
abstractHealthCheckConfig = JSON.parseObject(object.getString("healthChecker"), AbstractHealthChecker.Tcp.class);
} else if (type.equals(HealthCheckType.MYSQL.name())) {
abstractHealthCheckConfig = JSON.parseObject(object.getString("healthChecker"), AbstractHealthChecker.Mysql.class);
} else {
throw new IllegalArgumentException("can not prase cluster from json: " + json);
}
Cluster cluster = JSON.parseObject(json, Cluster.class);
cluster.setHealthChecker(abstractHealthCheckConfig);
return cluster;
}
代码示例来源:origin: hs-web/hsweb-framework
@Override
public SingleDictParser build(String config) {
Objects.requireNonNull(config, "config is null");
JSONObject object = JSON.parseObject(config);
String type = object.getString("type");
switch (type) {
case "simple":
return object.getObject("parser", SimpleSingleDictParser.class);
case "script":
// TODO: 17-5-25
default:
throw new UnsupportedOperationException(config);
}
}
}
代码示例来源:origin: alibaba/canal
@Override
protected RdsBackupPolicy processResult(HttpResponse response) throws Exception {
String result = EntityUtils.toString(response.getEntity());
JSONObject jsonObj = JSON.parseObject(result);
RdsBackupPolicy policy = new RdsBackupPolicy();
policy.setBackupRetentionPeriod(jsonObj.getString("BackupRetentionPeriod"));
policy.setBackupLog(jsonObj.getString("BackupLog").equalsIgnoreCase("Enable"));
policy.setLogBackupRetentionPeriod(jsonObj.getIntValue("LogBackupRetentionPeriod"));
policy.setPreferredBackupPeriod(jsonObj.getString("PreferredBackupPeriod"));
policy.setPreferredBackupTime(jsonObj.getString("PreferredBackupTime"));
return policy;
}
}
代码示例来源:origin: alibaba/nacos
@NeedAuth
@RequestMapping("/publish")
public String publish(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Encode", "gzip");
String entity = IOUtils.toString(request.getInputStream(), "UTF-8");
String value = Arrays.asList(entity).toArray(new String[1])[0];
value = URLDecoder.decode(value, "UTF-8");
JSONObject json = JSON.parseObject(value);
RaftCore.doSignalPublish(json.getString("key"), json.getString("value"), json.getBooleanValue("locked"));
return "ok";
}
代码示例来源:origin: ScienJus/smartqq
/**
* 获得好友的详细信息
*
* @return
*/
public UserInfo getFriendInfo(long friendId) {
LOGGER.debug("开始获取好友信息");
Response<String> response = get(ApiURL.GET_FRIEND_INFO, friendId, vfwebqq, psessionid);
return JSON.parseObject(getJsonObjectResult(response).toJSONString(), UserInfo.class);
}
代码示例来源:origin: hs-web/hsweb-framework
@Override
public CandidateDimension parse(DimensionContext context, String jsonConfig) {
JSONArray jsonArray;
if (jsonConfig.startsWith("[")) {
jsonArray = JSON.parseArray(jsonConfig);
} else {
JSONObject jsonObject = JSON.parseObject(jsonConfig);
jsonArray = new JSONArray();
jsonArray.add(jsonObject);
}
return parse(context, jsonArray);
}
}
代码示例来源: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: hs-web/hsweb-framework
@Override
public AuthenticationBuilder json(String json) {
JSONObject jsonObject = JSON.parseObject(json);
user(jsonObject.getObject("user", SimpleUser.class));
role(jsonObject.getJSONArray("roles").toJSONString());
permission(jsonObject.getJSONArray("permissions").toJSONString());
return this;
}
代码示例来源:origin: hs-web/hsweb-framework
private List<Object> parseArray(String json) {
if (!StringUtils.hasText(json)) {
return null;
}
return JSON.parseArray(json);
}
代码示例来源:origin: hs-web/hsweb-framework
protected JobDataMap createJobDataMap(String parameters) {
JobDataMap map = new JobDataMap();
if (!StringUtils.isEmpty(parameters)) {
JSONArray jsonArray = JSON.parseArray(parameters);
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject o = jsonArray.getJSONObject(i);
map.put(o.getString("key"), o.get("value"));
}
}
return map;
}
代码示例来源:origin: alibaba/nacos
@NeedAuth
@RequestMapping("/onPublish")
public String onPublish(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Encode", "gzip");
String entity = IOUtils.toString(request.getInputStream(), "UTF-8");
String value = Arrays.asList(entity).toArray(new String[1])[0];
value = URLDecoder.decode(value, "UTF-8");
JSONObject jsonObject = JSON.parseObject(value);
RaftCore.onPublish(jsonObject, jsonObject.getBoolean("increaseTerm"));
return "ok";
}
内容来源于网络,如有侵权,请联系作者删除!