Java Code Examples for com.alibaba.fastjson.JSON#parseObject()
The following examples show how to use
com.alibaba.fastjson.JSON#parseObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonStringBuilderTest.java From sofa-tracer with Apache License 2.0 | 6 votes |
@Test public void testAppendObject() throws Exception { JsonStringBuilder jsonStringBuilder = new JsonStringBuilder(); jsonStringBuilder.appendBegin(); jsonStringBuilder.append("sub", "sub"); jsonStringBuilder.append("su1", "sub1"); jsonStringBuilder.appendEnd(false); String sub = jsonStringBuilder.toString(); JSONObject subObject = JSON.parseObject(sub); assertEquals(2, subObject.size()); assertFalse(sub.endsWith(StringUtils.NEWLINE)); // JsonStringBuilder jsonStringBuilder1 = new JsonStringBuilder(); jsonStringBuilder1.appendBegin(); jsonStringBuilder1.append("key", "value"); jsonStringBuilder1.append("key1", "value1"); jsonStringBuilder1.append("key2", "value2"); jsonStringBuilder1.appendEnd("child", sub); String jsonStr = jsonStringBuilder1.toString(); JSONObject jsonObject = JSON.parseObject(jsonStr); assertEquals(4, jsonObject.size()); }
Example 2
Source File: ElasticsearchTransportFactory.java From database-transform-tool with Apache License 2.0 | 6 votes |
public String bulkUpsert(String index,String type,List<Object> jsons){ try { if(client==null){ init(); } BulkRequestBuilder bulkRequest = client.prepareBulk(); for (Object json : jsons) { JSONObject obj = JSON.parseObject(JSON.toJSONString(json)); String id = UUIDs.base64UUID(); if(obj.containsKey("id")){ id = obj.getString("id"); obj.remove("id"); bulkRequest.add(client.prepareUpdate(index, type, id).setDoc(obj.toJSONString(),XContentType.JSON)); }else{ bulkRequest.add(client.prepareIndex(index, type, id).setSource(obj.toJSONString(),XContentType.JSON)); } } BulkResponse result = bulkRequest.execute().get(); return result.toString(); }catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
Example 3
Source File: JsonMessageConverter.java From DDMQ with Apache License 2.0 | 5 votes |
@Override public Object read(Type type, // Class<?> contextClass, // HttpInputMessage inputMessage // ) throws IOException, HttpMessageNotReadableException { byte[] bodyBytes = getBody(inputMessage); if (bodyBytes == null || bodyBytes.length == 0) { return null; } return JSON.parseObject(bodyBytes, 0, bodyBytes.length, getFastJsonConfig().getCharset(), getType(type, contextClass), getFastJsonConfig().getFeatures()); }
Example 4
Source File: GitHubService.java From ApiManager with GNU Affero General Public License v3.0 | 5 votes |
public GitHubUser getUser(String accessToken) throws Exception{ String url = "https://api.github.com/user?access_token="+accessToken; String rs = HttpPostGet.get(url, null, null, 6000); if(rs.contains("message")){ throw new MyException(MyError.E000026, rs); } return JSON.parseObject(rs,GitHubUser.class); }
Example 5
Source File: CommonAuthorityServiceCache.java From momo-cloud-permission with Apache License 2.0 | 5 votes |
public List<AclLevelRes> dynamicMenuTree(DynamicMenuAuthorReq loginAuthReq, RedisUser redisUser) { List<AclDO> userAclList = commonSysCoreServiceCache.getUserAclList(loginAuthReq, redisUser); //获取第三方管理员权限id列表 String redisAdminKey = RedisKeyEnum.REDIS_ADMIN_ROLE_STR.getKey() + redisUser.getTenantId(); Object roleDoObj = redisUtil.get(redisAdminKey); if (null == roleDoObj) { return Lists.newArrayList(); } RoleDO roleDO = JSON.parseObject(String.valueOf(roleDoObj), new TypeReference<RoleDO>() { }); if (roleDO.getDisabledFlag().equals(1) || roleDO.getDelFlag().equals(1)) { return Lists.newArrayList(); } Object aclIdsObj = redisUtil.hget(RedisKeyEnum.REDIS_ROLE_ACLS_MAP.getKey() + roleDO.getId(), loginAuthReq.getAclPermissionCode()); if (null == aclIdsObj) { return Lists.newArrayList(); } List<Long> adminAclIds = JSON.parseObject(String.valueOf(aclIdsObj), new TypeReference<List<Long>>() { }); if (CollectionUtils.isEmpty(adminAclIds)) { return Lists.newArrayList(); } List<AclLevelRes> aclDtoList = Lists.newArrayList(); for (AclDO acl : userAclList) { //权限继承 //企业员工权限列表不能大于该企业下管理员(老板)权限列表 if (acl.getDisabledFlag().equals(0) && acl.getDelFlag().equals(0)) { if (adminAclIds.contains(acl.getId())) { AclLevelRes dto = AclLevelRes.adapt(acl); dto.setHasAcl(true); dto.setDisabled(false); dto.setChecked(true); aclDtoList.add(dto); } } } return aclListToTree(aclDtoList); }
Example 6
Source File: RwController.java From OfficeAutomatic-System with Apache License 2.0 | 5 votes |
/** * 添加日志 * @param rz * @return */ @RequestMapping(value = "/addRz") @ResponseBody @CrossOrigin public JSONObject addRz(Rz rz) { try{ rwService.addRz(rz); }catch (Exception e){ return JSON.parseObject("{success:false,msg:\"添加日志失败!\"}"); } return JSON.parseObject("{success:true,msg:\"添加日志成功!\"}"); }
Example 7
Source File: MirrativLiveService.java From Alice-LiveMan with GNU Affero General Public License v3.0 | 5 votes |
@Override public VideoInfo getLiveVideoInfo(URI videoInfoUrl, ChannelInfo channelInfo,String resolution) throws Exception { if (videoInfoUrl == null) { return null; } String videoId = videoInfoUrl.toString().substring(GET_LIVE_INFO_URL.length()); String liveDetailJson = HttpRequestUtil.downloadUrl(new URI("https://www.mirrativ.com/api/live/live?live_id=" + videoId), channelInfo != null ? channelInfo.getCookies() : null, Collections.emptyMap(), StandardCharsets.UTF_8); JSONObject liveDetailObj = JSON.parseObject(liveDetailJson); String videoTitle = liveDetailObj.getString("title"); URI m3u8ListUrl = new URI(liveDetailObj.getString("streaming_url_hls")); String[] m3u8List = HttpRequestUtil.downloadUrl(m3u8ListUrl, StandardCharsets.UTF_8).split("\n"); String mediaUrl = m3u8List[3]; return new VideoInfo(channelInfo, videoId, videoTitle, videoInfoUrl, m3u8ListUrl.resolve(mediaUrl), "m3u8"); }
Example 8
Source File: AndroidScrcpySocketServer.java From agent with MIT License | 5 votes |
@OnMessage public void onMessage(String msg) { JSONObject message = JSON.parseObject(msg); String operation = message.getString("operation"); switch (operation) { case "m": scrcpy.moveTo(message.getInteger("x"), message.getInteger("y"), message.getInteger("width"), message.getInteger("height")); break; case "d": scrcpy.touchDown(message.getInteger("x"), message.getInteger("y"), message.getInteger("width"), message.getInteger("height")); break; case "u": scrcpy.touchUp(message.getInteger("x"), message.getInteger("y"), message.getInteger("width"), message.getInteger("height")); break; case "home": scrcpy.home(); break; case "back": scrcpy.back(); break; case "power": scrcpy.power(); break; case "menu": scrcpy.menu(); break; } }
Example 9
Source File: AbstractHttpRequest.java From gecco with MIT License | 5 votes |
@Override protected Object clone() throws CloneNotSupportedException { //通过json的序列号和反序列化实现对象的深度clone String text = JSON.toJSONString(this); //序列化 HttpRequest request = JSON.parseObject(text, this.getClass()); //反序列化 return request; }
Example 10
Source File: DemoClusterInitFunc.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
private void initStateProperty() { // Cluster map format: // [{"clientSet":["112.12.88.66@8729","112.12.88.67@8727"],"ip":"112.12.88.68","machineId":"112.12.88.68@8728","port":11111}] // machineId: <ip@commandPort>, commandPort for port exposed to Sentinel dashboard (transport module) ReadableDataSource<String, Integer> clusterModeDs = new NacosDataSource<>(remoteAddress, groupId, clusterMapDataId, source -> { List<ClusterGroupEntity> groupList = JSON.parseObject(source, new TypeReference<List<ClusterGroupEntity>>() {}); return Optional.ofNullable(groupList) .map(this::extractMode) .orElse(ClusterStateManager.CLUSTER_NOT_STARTED); }); ClusterStateManager.registerProperty(clusterModeDs.getProperty()); }
Example 11
Source File: BurpSuiteApp.java From TrackRay with GNU General Public License v3.0 | 5 votes |
@Function public void doProxy(){ ProxyServer proxyServer = JSON.parseObject(JSON.toJSONString(param), ProxyServer.class); JSONObject servers = JSON.parseObject("{\n" + " \"project_options\": {\n" + " \"connections\": {\n" + " \"upstream_proxy\": {\n" + " \"servers\": [\n" + " ],\n" + " \"use_user_options\":false\n" + " }\n" + " }\n" + " }\n" + "}"); JSONArray arr = servers.getJSONObject("project_options").getJSONObject("connections").getJSONObject("upstream_proxy").getJSONArray("servers"); arr.add(proxyServer); String json = servers.toJSONString(); int serverPort = burpSuite.getServerPort(); String url = "http://" + burpSuite.getServerAddress() + ":" + serverPort+"/burp/configuration"; try { HttpResponse post = requests.url(url).data(json).method(HttpRequest.Method.PUT).request(); int statusCode = post.getStatusCode(); if (statusCode==200){ write("{\"msg\":\"修改成功\"}"); return; } } catch (MalformedURLException e) { write("{\"msg\":\""+e.getMessage()+"\"}"); return; } write("{\"msg\":\"修改失败\"}"); }
Example 12
Source File: MessageDecoder.java From lightconf with GNU General Public License v3.0 | 5 votes |
@Override protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception { //这个HEAD_LENGTH是我们用于表示头长度的字节数 if (byteBuf.readableBytes() < CommonConstants.HEAD_LENGTH) { return; } //我们标记一下当前的readIndex的位置 byteBuf.markReaderIndex(); // 读取传送过来的消息的长度。ByteBuf 的readInt()方法会让他的readIndex增加4 int dataLength = byteBuf.readInt(); // 我们读到的消息体长度为0,这是不应该出现的情况,这里出现这情况,关闭连接。 if (dataLength < 0) { channelHandlerContext.close(); } //读到的消息体长度如果小于我们传送过来的消息长度,则resetReaderIndex. 这个配合markReaderIndex使用的。把readIndex重置到mark的地方 if (byteBuf.readableBytes() < dataLength) { byteBuf.resetReaderIndex(); return; } byte[] body = new byte[dataLength]; byteBuf.readBytes(body); //将byte数据转化为我们需要的对象 BaseMsg baseMsg = JSON.parseObject(body,BaseMsg.class); list.add(baseMsg); }
Example 13
Source File: FeedsSchedule.java From rebuild with GNU General Public License v3.0 | 5 votes |
@Override public JSON build() { Object[][] array = Application.createQueryNoFilter( "select feedsId,scheduleTime,content,contentMore from Feeds" + " where createdBy = ? and type = 4 and scheduleTime > ? order by scheduleTime") .setParameter(1, getUser()) .setParameter(2, CalendarUtils.addDay(-30)) // 忽略30天前的 .setLimit(200) .array(); final long nowTime = CalendarUtils.now().getTime(); JSONArray list = new JSONArray(); for (Object[] o : array) { // 有完成时间表示已完成 JSONObject state = JSON.parseObject((String) o[3]); if (state.getString("finishTime") != null) { continue; } final Date date = (Date) o[1]; String scheduleTime = CalendarUtils.getUTCDateTimeFormat().format(date).substring(0, 16); String fromNow = Moment.moment(date).fromNow(); if (nowTime > date.getTime()) { fromNow = "-" + fromNow; } String content = (String) o[2]; content = MessageBuilder.formatMessage(content); JSONObject item = JSONUtils.toJSONObject( new String[] { "id", "scheduleTime", "scheduleLeft", "content" }, new Object[] { o[0], scheduleTime, fromNow, content }); list.add(item); } return list; }
Example 14
Source File: FastJson2JsonRedisSerializer.java From open-capacity-platform with Apache License 2.0 | 5 votes |
@Override public T deserialize(byte[] bytes) throws SerializationException { if (bytes == null || bytes.length <= 0) { return null; } String str = new String(bytes, DEFAULT_CHARSET); return (T) JSON.parseObject(str, clazz); }
Example 15
Source File: SimpleHintParser.java From tddl5 with Apache License 2.0 | 4 votes |
public static RouteCondition convertHint2RouteCondition(String sql, Map<Integer, ParameterContext> parameterSettings) { // 检查下thread local hint RouteCondition condition = getRouteContiongFromThreadLocal(ThreadLocalString.ROUTE_CONDITION); if (condition != null) { return condition; } condition = getRouteContiongFromThreadLocal(ThreadLocalString.DB_SELECTOR); if (condition != null) { return condition; } OldHintParser.checkOldThreadLocalHint(); String tddlHint = extractHint(sql, parameterSettings); if (StringUtils.isNotEmpty(tddlHint)) { if (tddlHint.contains("type:executeBy") || tddlHint.contains("type:'executeBy")) { // 使用老hint RouteCondition routeCondition = OldHintParser.extractHint(tddlHint); if (routeCondition != null) { return routeCondition; } } try { JSONObject jsonObject = JSON.parseObject(tddlHint); String type = jsonObject.getString(TYPE); if (TYPE_DIRECT.equalsIgnoreCase(type)) { return decodeDirect(jsonObject); } else if (TYPE_CONDITION.equalsIgnoreCase(type)) { return decodeCondition(jsonObject); } else { return decodeExtra(jsonObject); } } catch (JSONException e) { logger.error("convert tddl hint to RouteContion faild,check the hint string!", e); throw e; } } return null; }
Example 16
Source File: JsonUtil.java From jframe with Apache License 2.0 | 4 votes |
public static <T> T fromJson(String json, Class<T> clazz) { if (json == null || "".equals(json)) return null; return JSON.parseObject(json, clazz); }
Example 17
Source File: FastJsonKit.java From jfinal-ext3 with Apache License 2.0 | 4 votes |
public static <T> T parse(String jsonString, Class<T> type) { return JSON.parseObject(jsonString, type); }
Example 18
Source File: HostApplication.java From Router-RePlugin with Apache License 2.0 | 4 votes |
@Override public Update parse(String httpResponse) throws Exception { return JSON.parseObject(httpResponse, Update.class); }
Example 19
Source File: PostServerApi.java From LuckyFrameClient with GNU Affero General Public License v3.0 | 4 votes |
/** * ɾ������ִ����־ * @param taskId ����ID * @param caseId ����ID */ public static void clientDeleteTaskCaseLog(Integer taskId, Integer caseId){ String str = "{\"taskId\":"+taskId+",\"caseId\":"+caseId+"}"; JSONObject jsonObject = JSON.parseObject(str); HttpRequest.httpClientPostJson(PREFIX + "/clientDeleteTaskCaseLog", jsonObject.toJSONString()); }
Example 20
Source File: JSONUtil.java From netty-file-parent with Apache License 2.0 | 2 votes |
/** * 把json字符串转化为相应的实体对象 * @param json * @param clazz * @return * @author:landyChris */ public static <T> T parseObject(String json, Class<T> clazz) { return JSON.parseObject(json, clazz); }