Java Code Examples for com.alibaba.fastjson.JSONObject#parse()

The following examples show how to use com.alibaba.fastjson.JSONObject#parse() . 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: ViewChildListener.java    From dble with GNU General Public License v2.0 6 votes vote down vote up
/**
 * update the meta if the view updated
 */
private void createOrUpdateViewMeta(ChildData childData, boolean isReplace) throws Exception {
    String path = childData.getPath();
    String[] paths = path.split("/");
    String jsonValue = new String(childData.getData(), StandardCharsets.UTF_8);
    JSONObject obj = (JSONObject) JSONObject.parse(jsonValue);

    //if the view is create or replace by this server it self
    String serverId = obj.getString(SERVER_ID);
    if (serverId.equals(ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
        return;
    }
    String createSql = obj.getString(CREATE_SQL);
    String schema = paths[paths.length - 1].split(SCHEMA_VIEW_SPLIT)[0];

    ViewMeta vm = new ViewMeta(schema, createSql, ProxyMeta.getInstance().getTmManager());
    vm.init(isReplace);
    vm.addMeta(false);

}
 
Example 2
Source File: DownloadPicture.java    From Gather-Platform with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void process(Page page) {
    List<String> url_list = new ArrayList<>();
    List<String> name_list = new ArrayList<>();
    JSONObject jsonObject = (JSONObject) JSONObject.parse(page.getRawText());
    JSONArray data = (JSONArray) jsonObject.get("imgs");
    for(int i=0;i<data.size();i++){
        String url = (String) data.getJSONObject(i).get("objURL");
        String name = (String) data.getJSONObject(i).get("fromPageTitleEnc");
        if(url!=null){
            url_list.add(url);
            name_list.add(name);
        }
    }
    setUrls(url_list);
    setNames(name_list);
}
 
Example 3
Source File: WXStreamModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
Object parseData(String data, Options.Type type) throws JSONException{
  if( type == Options.Type.json){
    return JSONObject.parse(data);
  }else if( type == Options.Type.jsonp){
    if(data == null || data.isEmpty()) {
      return new JSONObject();
    }
    int b = data.indexOf("(")+1;
    int e = data.lastIndexOf(")");
    if(b ==0 || b >= e || e <= 0){
      return new JSONObject();
    }

    data = data.substring(b,e);
    return JSONObject.parse(data);
  }else {
    return data;
  }
}
 
Example 4
Source File: KVStoreRepository.java    From dble with GNU General Public License v2.0 6 votes vote down vote up
public void init() {
    Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
    try {
        List<String> viewList = zkConn.getChildren().forPath(KVPathUtil.getViewPath());
        for (String singlePath : viewList) {
            String[] paths = singlePath.split("/");
            String jsonData = new String(zkConn.getData().forPath(KVPathUtil.getViewPath() + SEPARATOR + singlePath), "UTF-8");
            JSONObject obj = (JSONObject) JSONObject.parse(jsonData);

            String createSql = obj.getString(CREATE_SQL);
            String schema = paths[paths.length - 1].split(SCHEMA_VIEW_SPLIT)[0];
            String viewName = paths[paths.length - 1].split(SCHEMA_VIEW_SPLIT)[1];
            if (map.get(schema) == null) {
                map.put(schema, new HashMap<String, String>());
            }
            map.get(schema).put(viewName, createSql);
        }
    } catch (Exception e) {
        LOGGER.info("init viewData from zk error : " + e.getMessage());
    } finally {
        viewCreateSqlMap = map;
    }
}
 
Example 5
Source File: WXStreamModule.java    From weex-uikit with MIT License 6 votes vote down vote up
Object parseData(String data, Options.Type type) throws JSONException{
  if( type == Options.Type.json){
    return JSONObject.parse(data);
  }else if( type == Options.Type.jsonp){
    if(data == null || data.isEmpty()) {
      return new JSONObject();
    }
    int b = data.indexOf("(")+1;
    int e = data.lastIndexOf(")");
    if(b ==0 || b >= e || e <= 0){
      return new JSONObject();
    }

    data = data.substring(b,e);
    return JSONObject.parse(data);
  }else {
    return data;
  }
}
 
Example 6
Source File: WeixinReceivetextController.java    From jeewx-boot with Apache License 2.0 6 votes vote down vote up
/**
 * 查询聊天记录
 * @return
 */
@RequestMapping(value="queryChatLog",method = {RequestMethod.GET,RequestMethod.POST})
@ResponseBody
public AjaxJson queryChatLog(@RequestParam(required = true, value = "id" ) String id,HttpServletResponse response,HttpServletRequest request){
	AjaxJson j = new AjaxJson();
	try {
		WeixinReceivetext weixinReceivetext = weixinReceivetextService.queryById(id);
		List<Map<String,Object>> chats=weixinReceivetextService.queryAllChatLog(weixinReceivetext);
		//遍历查询结果,获取消息类型
		for(Map<String,Object> m:chats){
			String msgtype = (String) m.get("msgtype");
			String content = (String) m.get("content");
			if("image".equals(msgtype)){
				JSONObject json = (JSONObject) JSONObject.parse(content);
				m.put("content", json.getString("PicUrl"));
			}
		}
		j.setObj(chats);
	} catch (Exception e) {
		e.printStackTrace();
		log.error(e.getMessage());
		j.setSuccess(false);
		j.setMsg("获取消息失败");
	}
	return j;
}
 
Example 7
Source File: MediaMetaController.java    From DataLink with Apache License 2.0 6 votes vote down vote up
private static Object assembleJsonArray(String[] dbs, String[] tables, TableInfo[] columns,String msg) {
    ResponseInfo info = new ResponseInfo();
    if(dbs != null) {
        info.setDbs(dbs);
        info.setCount(dbs.length+"");
    }
    else if(tables != null) {
        info.setTables(tables);
        info.setCount(tables.length+"");
    }
    else if(columns != null) {
        info.setColumns(columns);
        info.setCount(columns.length+"");
    }
    else {
        info.setCount("-1");
    }
    info.setMsg(msg);
    String json = JSONObject.toJSONString(info);
    Object obj = JSONObject.parse(json);
    return obj;
}
 
Example 8
Source File: Record.java    From Aooms with Apache License 2.0 5 votes vote down vote up
public Record setByJsonKey(String jsonKey){
    String jsonStr = DataBoss.self().getPara().getString(jsonKey);
    if(StrUtil.isNotBlank(jsonStr)){
        JSONObject jsonObject = (JSONObject) JSONObject.parse(jsonStr);
        Set<String> keySet = jsonObject.keySet();
        for(String key : keySet){
            Object value = jsonObject.get(key);
            this.set(key,value);
        }
    }
    return this;
}
 
Example 9
Source File: JobConfigController.java    From DataLink with Apache License 2.0 5 votes vote down vote up
/**
 * 验证json是否有效
 *
 * @param json
 * @return
 */
private static boolean JsonVerfiy(String json) {
    if (StringUtils.isBlank(json)) {
        return false;
    }
    try {
        JSONObject.parse(json);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 10
Source File: RdbmsServiceController.java    From DataLink with Apache License 2.0 5 votes vote down vote up
public static Object assembleJsonArrayWithTableInfo(TableInfo[] infos, String msg) {
    ResponseInfo info = new ResponseInfo();
    info.setInfos(infos);
    info.setCount(infos.length+"");
    info.setMsg(msg);
    String json = JSONObject.toJSONString(info);
    Object obj = JSONObject.parse(json);
    return obj;
}
 
Example 11
Source File: IndexServiceImpl.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> show(String indexName) throws IOException {
    GetIndexRequest request = new GetIndexRequest();
    request.indices(indexName);
    GetIndexResponse getIndexResponse = elasticsearchRestTemplate.getClient()
            .indices().get(request, RequestOptions.DEFAULT);
    ImmutableOpenMap<String, MappingMetaData> mappOpenMap = getIndexResponse.getMappings().get(indexName);
    List<AliasMetaData> indexAliases = getIndexResponse.getAliases().get(indexName);

    String settingsStr = getIndexResponse.getSettings().get(indexName).toString();
    Object settingsObj = null;
    if (StrUtil.isNotEmpty(settingsStr)) {
        settingsObj = JSONObject.parse(settingsStr);
    }
    Map<String, Object> result = new HashMap<>(1);
    Map<String, Object> indexMap = new HashMap<>(3);
    Map<String, Object> mappMap = new HashMap<>(mappOpenMap.size());
    List<String> aliasesList = new ArrayList<>(indexAliases.size());
    indexMap.put("aliases", aliasesList);
    indexMap.put("settings", settingsObj);
    indexMap.put("mappings", mappMap);
    result.put(indexName, indexMap);
    //获取mappings数据
    for (ObjectCursor<String> key : mappOpenMap.keys()) {
        MappingMetaData data = mappOpenMap.get(key.value);
        Map<String, Object> dataMap = data.getSourceAsMap();
        mappMap.put(key.value, dataMap);
    }
    //获取aliases数据
    for (AliasMetaData aliases : indexAliases) {
        aliasesList.add(aliases.getAlias());
    }
    return result;
}
 
Example 12
Source File: NSBusiness.java    From ns4_gear_watchdog with Apache License 2.0 5 votes vote down vote up
public static void saveTradeDataToEs() {
    try {
        MBeanServerConnection mbsc = Jmx.getInstance().getChildJmx().getMbServerConnection();
        MonitorDataMXBean proxy = JmxUtil.getMonitorDataMXBean(mbsc);
        String nstradeMessage = proxy.getData(MessageType.NS_TRADE_MESSAGE.name());
        logger.info("获取业务数据{} ", nstradeMessage);
        if (null != nstradeMessage && !"".equals(nstradeMessage)) {
            logger.info("保存业务数据{} ", nstradeMessage);
            ESUtil util = new ESUtil();
            Map<String, List<Object>> strtomap = (Map<String, List<Object>>) JSONObject.parse(nstradeMessage);
            if (strtomap != null && strtomap.size() != 0) {
                logger.info("循环保存业务数据{} ", nstradeMessage);
                Iterator<String> iterator = strtomap.keySet().iterator();
                while (iterator.hasNext()) {
                    String msgId = iterator.next();
                    List<Object> msgList = strtomap.get(msgId);
                    for (Object event : msgList) {
                        Map<String, Object> msgMap = new HashMap<String, Object>();
                        msgMap.put("msgId", msgId);
                        msgMap.put("content", event);
                        util.addDocument(PropertiesUtil.getValue("elastic.esindices"), PropertiesUtil.getValue("elastic.estype"), msgMap);
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.error("获取接收队列异常:{} {}", e.getMessage(), e);
    }
}
 
Example 13
Source File: EntityCronUtil.java    From DataLink with Apache License 2.0 5 votes vote down vote up
public static long startResultParse(String startResult) {
    JSONObject obj = (JSONObject)JSONObject.parse(startResult);
    String msg = (String)obj.get("msg");
    if( !SUCCESS.equals(msg) ) {
        return -1L;
    }
    String value = (String)obj.get("executId");
    if(value!=null && value.contains("_")) {
        return Long.parseLong(value.split("_")[0]);
    } else if(value != null) {
        return Long.parseLong(value);
    } else {
        return -1L;
    }
}
 
Example 14
Source File: ESJobConfigServiceImpl.java    From DataLink with Apache License 2.0 5 votes vote down vote up
private String processReaderExtendJson(String json, Map<String, String> srcExtendJson) {
    if(srcExtendJson==null || srcExtendJson.size()==0) {
        return json;
    }
    String extendJson = JSONObject.toJSONString(srcExtendJson);
    ElasticSearchJobExtendProperty jobExtend = JSONObject.parseObject(extendJson,ElasticSearchJobExtendProperty.class);
    DLConfig connConf = DLConfig.parseFrom(json);
    if(StringUtils.isNotBlank( jobExtend.getEsReaderIndexType()) ) {
        String indexType = jobExtend.getEsReaderIndexType();
        String[] arr = indexType.split("\\.");
        if(arr!=null && arr.length==2) {
            connConf.set("job.content[0].reader.parameter.esIndex", arr[0]);
            connConf.set("job.content[0].reader.parameter.esType", arr[1]);
        }
        else if(arr!=null && arr.length==1) {
            connConf.set("job.content[0].reader.parameter.esIndex", arr[0]);
            connConf.set("job.content[0].reader.parameter.esType", arr[0]);
        }
    }

    if(StringUtils.isNotBlank( jobExtend.getEsReaderQuery()) ) {
        String query = jobExtend.getEsReaderQuery();
        Object jsonQuery = JSONObject.parse(query);
        connConf.set("job.content[0].reader.parameter.esQuery",jsonQuery);
    }
    return json = connConf.toJSON();
}
 
Example 15
Source File: WeixinReceivetextServiceImpl.java    From jeewx-boot with Apache License 2.0 5 votes vote down vote up
@Override
public PageList<WeixinReceivetext> queryPageList(
	PageQuery<WeixinReceivetext> pageQuery) {
	PageList<WeixinReceivetext> result = new PageList<WeixinReceivetext>();
	Integer itemCount = weixinReceivetextDao.count(pageQuery);
	PageQueryWrapper<WeixinReceivetext> wrapper = new PageQueryWrapper<WeixinReceivetext>(pageQuery.getPageNo(), pageQuery.getPageSize(),itemCount, pageQuery.getQuery());
	List<WeixinReceivetext> list = weixinReceivetextDao.queryPageList(wrapper);
	//遍历查询结果,获取消息类型
	for(WeixinReceivetext w:list){
		if(w.getMsgType().equals("text")){					//文本消息
			continue;
		}else if(w.getMsgType().equals("news")){			//图文消息
			continue;
		}else if(w.getMsgType().equals("voice")){			//音频消息
			continue;
		}else if(w.getMsgType().equals("video")){			//视频消息
			continue;
		}else if(w.getMsgType().equals("image")){			//图片消息
			JSONObject json = (JSONObject) JSONObject.parse(w.getContent());
			w.setContent(json.getString("PicUrl"));
			continue;
		}else if(w.getMsgType().equals("event")){			//事件消息
			continue;
		}else if(w.getMsgType().equals("shortvideo")){		//小视频消息
			continue;
		}else if(w.getMsgType().equals("link")){			//链接消息
			continue;
		}else if(w.getMsgType().equals("location")){		//地理位置消息
			continue;
		}
	}
	Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
	result.setPagenation(pagenation);
	result.setValues(list);
	return result;
}
 
Example 16
Source File: AbstractServiceApiPlusListener.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/**
 * 提前提交事务
 *
 * @param dataFlowContext
 */
public void commit(DataFlowContext dataFlowContext) {

    JSONArray businesses = dataFlowContext.getServiceBusiness();

    if (businesses == null || businesses.size() < 1) {
        return;
    }

    //服务合并处理
    JSONObject paramIn = mergeService(dataFlowContext);

    ResponseEntity<String> responseEntity = this.callOrderService(dataFlowContext, paramIn);

    //组装符合要求报文
    ResultVo resultVo = null;

    if (responseEntity.getStatusCode() != HttpStatus.OK) {
        resultVo = new ResultVo(ResultVo.ORDER_ERROR, responseEntity.getBody());
    } else {
        String orderResult = responseEntity.getBody();
        if (orderResult.startsWith("{")) {
            resultVo = new ResultVo(ResultVo.CODE_OK, ResultVo.MSG_OK, JSONObject.parse(orderResult));
        } else {
            resultVo = new ResultVo(ResultVo.CODE_OK, ResultVo.MSG_OK, JSONArray.parse(orderResult));
        }
    }

    if (dataFlowContext.getResponseEntity() == null) {
        responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        dataFlowContext.setResponseEntity(responseEntity);
    }

    dataFlowContext.setServiceBusiness(new JSONArray());

}
 
Example 17
Source File: WeixinReceivetextController.java    From jeewx-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 查询聊天记录
 * @return
 */
@RequestMapping(value="queryMoreChatLog",method = {RequestMethod.GET,RequestMethod.POST})
@ResponseBody
public AjaxJson queryMoreChatLog(@RequestParam(required = true, value = "id" ) String id,HttpServletResponse response,HttpServletRequest request){
	AjaxJson j = new AjaxJson();
	try {
		String firstRecordTime = request.getParameter("firstRecordTime");
		WeixinReceivetext weixinReceivetext = weixinReceivetextService.queryById(id);
		List<Map<String,Object>> chats=weixinReceivetextService.queryMoreChatLog(weixinReceivetext,firstRecordTime);
		//遍历查询结果,获取消息类型
		for(Map<String,Object> m:chats){
			String msgtype = (String) m.get("msgtype");
			String content = (String) m.get("content");
			if("image".equals(msgtype)){
				JSONObject json = (JSONObject) JSONObject.parse(content);
				m.put("content", json.getString("PicUrl"));
			}
		}
		j.setObj(chats);
	} catch (Exception e) {
		e.printStackTrace();
		log.error(e.getMessage());
		j.setSuccess(false);
		j.setMsg("获取消息失败");
	}
	return j;
}
 
Example 18
Source File: UploadFileUtils.java    From albert with MIT License 4 votes vote down vote up
/**
* 
* @param request 网页请求
* @param avatar_file  avatar_file(源文件)
* @param avatar_data avatar_data(裁剪参数JSON
* @param dir 地址名称
* @return 
*/
  public static Map<String, Object> Upload(HttpServletRequest request, MultipartFile avatar_file, String avatar_data, String dir){
  	Map<String, Object> returnMap = new HashMap<String, Object>();
  	//获取服务器的实际路径
  	String serverSaveDir = getServerSaveDir(request, dir);
  	//生成文件名称
  	String newFileName = rename(avatar_file);
  	
      //先把用户上传到原图保存到服务器上  
      File targetFile = new File(serverSaveDir, newFileName);
      boolean flag = false;
      try{
      	//创建JSONObject对象
          JSONObject joData = (JSONObject) JSONObject.parse(avatar_data);
          // 用户经过剪辑后的图片的大小  
          float x = joData.getFloatValue("x");
          float y = joData.getFloatValue("y");
          float w =  joData.getFloatValue("width");
          float h =  joData.getFloatValue("height");
          float r = joData.getFloatValue("rotate");
      	
          //将文件剪辑并上传到服务器上和本地文件中
          if(!targetFile.exists()){  
              targetFile.mkdirs(); 
              //获取文件流,可以进行处理
              InputStream is = avatar_file.getInputStream();
              //旋转后剪裁图片
              ImageUtils.cutAndRotateImage(is, targetFile, (int)x,(int)y,(int)w,(int)h,(int)r); 
              //关闭该流并释放与该流关联的所有系统资源。
              is.close();
              flag = true;
          }  
      }catch(Exception e){
          e.printStackTrace();  
      }
      String a = serverSaveDir.replaceAll("\\\\", "/");
      String[] options = a.split( "uploadimage/");
      returnMap.put("savaPath", options[1]+"/"+ newFileName);
      returnMap.put("flag", flag);
return returnMap;
  }
 
Example 19
Source File: JsonUserType.java    From es with Apache License 2.0 3 votes vote down vote up
/**
 * 从JDBC ResultSet读取数据,将其转换为自定义类型后返回
 * (此方法要求对克能出现null值进行处理)
 * names中包含了当前自定义类型的映射字段名称
 *
 * @param names
 * @param owner
 * @return
 * @throws org.hibernate.HibernateException
 * @throws java.sql.SQLException
 */
@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
    String valueStr = rs.getString(names[0]);
    if (StringUtils.isEmpty(valueStr)) {
        return null;
    }

    return JSONObject.parse(valueStr);
}
 
Example 20
Source File: JsonUserType.java    From es with Apache License 2.0 3 votes vote down vote up
/**
 * 提供自定义类型的完全复制方法
 * 本方法将用构造返回对象
 * 当nullSafeGet方法调用之后,我们获得了自定义数据对象,在向用户返回自定义数据之前,
 * deepCopy方法将被调用,它将根据自定义数据对象构造一个完全拷贝,并将此拷贝返回给用户
 * 此时我们就得到了自定义数据对象的两个版本,第一个是从数据库读出的原始版本,其二是我们通过
 * deepCopy方法构造的复制版本,原始的版本将有Hibernate维护,复制版由用户使用。原始版本用作
 * 稍后的脏数据检查依据;Hibernate将在脏数据检查过程中将两个版本的数据进行对比(通过调用
 * equals方法),如果数据发生了变化(equals方法返回false),则执行对应的持久化操作
 *
 * @param o
 * @return
 * @throws org.hibernate.HibernateException
 */
@Override
public Object deepCopy(Object o) throws HibernateException {
    if (o == null) return null;
    String jsonStr = JSONObject.toJSONString(o, SerializerFeature.WriteClassName);
    return JSONObject.parse(jsonStr);
}