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

The following examples show how to use com.alibaba.fastjson.JSONObject#size() . These examples are extracted from open source projects. 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 Project: ES-Fastloader   File: TypeProperties.java    License: Apache License 2.0 6 votes vote down vote up
public TypeProperties(JSONObject root) {
    for(String key : root.keySet()) {
        JSONObject obj = root.getJSONObject(key);

        if(obj.containsKey(PROPERTIES_STR)) {
            propertyMap.put(key, new TypeProperties(obj.getJSONObject(PROPERTIES_STR)));

            // 处理nest本省有类型的情况
            JSONObject o = JSON.parseObject(obj.toJSONString());
            o.remove(PROPERTIES_STR);
            if(o.size()>0) {
                propertyTypeMap.put(key, new TypeDefine(o));
            }

        } else {
            jsonMap.put(key, new TypeDefine(obj));
        }
    }
}
 
Example 2
/**
* getList(获取微信留言带分页数据-服务)
   * @author rufei.cn
   * @param json
* @return
*/
@RequestMapping("getList")
public Partion  getList(@RequestBody JSONObject json)
{
      logger.info("getList(获取微信留言带分页数据-服务) 开始 json={}", json);
      if(json==null||json.size()<1)
      {
         return null;
      }
      int totalcount =commentHelperService.getTotalCount(json);
      List<Comment> list= null;
      if(totalcount>0)
      {
         list= commentDao.getList(json);
      }
      Partion pt = new Partion(json, list, totalcount);
logger.info("getList(获取微信留言带分页数据-服务) 结束 ");
return pt;
}
 
Example 3
/**
 * 增加高亮词
 *
 * @param keywords
 * @param highlightBuilder
 */
private void AddHighLigh(JSONObject keywords, HighlightBuilder highlightBuilder) {
    if (keywords == null || keywords.size() <= 0) {
        return;
    }
    Iterator<Map.Entry<String, Object>> iterator = keywords.entrySet().iterator();
    if (iterator == null) {
        return;
    }
    while (iterator.hasNext()) {
        Map.Entry<String, Object> next = iterator.next();
        String key = next.getKey();
        Object value = next.getValue();
        if (value == null || value.toString().length() <= 0) {
            continue;
        }
        highlightBuilder.preTags("<span style=color:red>");
        highlightBuilder.postTags("</span>");
        highlightBuilder.field(key);
    }
}
 
Example 4
Source Project: xmfcn-spring-cloud   File: MusicService.java    License: Apache License 2.0 6 votes vote down vote up
/**
* getList(获取微信音乐带分页数据-服务)
   * @author rufei.cn
   * @param json
* @return
*/
@RequestMapping("getList")
public Partion getList(@RequestBody JSONObject json)
{
      logger.info("getList(获取微信音乐带分页数据-服务) 开始 json={}", json);
      if(json==null||json.size()<1)
      {
         return null;
      }
      int totalcount =musicHelperService.getTotalCount(json);
      List<Music> list= null;
      if(totalcount>0)
      {
         list= musicDao.getList(json);
      }
      Partion pt = new Partion(json, list, totalcount);
logger.info("getList(获取微信音乐带分页数据-服务) 结束 ");
return pt;
}
 
Example 5
Source Project: weex   File: WXDomModule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Update {@link WXDomObject#attr}
 * @param ref {@link WXDomObject#ref}
 * @param attr the expected attr
 */
@WXModuleAnno(moduleMethod = true, runOnUIThread = false)
public void updateAttrs(String ref, JSONObject attr) {
  if (TextUtils.isEmpty(ref) || attr == null || attr.size() < 1) {
    return;
  }
  Message msg = Message.obtain();
  WXDomTask task = new WXDomTask();
  task.instanceId = mWXSDKInstance.getInstanceId();
  task.args = new ArrayList<>();
  task.args.add(ref);
  task.args.add(attr);
  msg.what = WXDomHandler.MsgType.WX_DOM_UPDATE_ATTRS;
  msg.obj = task;
  WXSDKManager.getInstance().getWXDomManager().sendMessage(msg);
}
 
Example 6
/**
 * 构造默认的日志规则
 * 
 * @param filterregex
 *            日志过滤规则的正则表达式
 * @param separator
 *            日志字段分隔符
 * @param fields
 *            日志字段名以及对应在的列号
 * @param fieldNumber
 *            指定对应的列号值为时间戳
 * @param version
 *            规则当前的版本
 */
public DefaultLogFilterAndRule(String filterregex, String separator, JSONObject fields, int fieldNumber,
        int version) {

    this.filterPattern = Pattern.compile(filterregex);

    this.separator = Splitter.on(separator).trimResults();
    this.SpecifiedFields = new Integer[fields.size()];
    this.fieldsName = new String[fields.size()];
    int i = 0;
    for (Entry<String, Object> entry : fields.entrySet()) {
        fieldsName[i] = entry.getKey();
        SpecifiedFields[i++] = (Integer) entry.getValue();
    }
    this.timeStampField = fieldNumber;

    this.version = version;

    @SuppressWarnings("rawtypes")
    List<Map> mainlogs = Lists.newLinkedList();

    setMainlogs(mainlogs);
}
 
Example 7
Source Project: xmfcn-spring-cloud   File: LikeService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * getList(获取微信点赞带分页数据-服务)
 *
 * @param json
 * @return
 * @author rufei.cn
 */
@RequestMapping("getList")
public Partion getList(@RequestBody JSONObject json) {
    logger.info("getList(获取微信点赞带分页数据-服务) 开始 json={}", json);
    if (json == null || json.size() < 1) {
        return null;
    }
    int totalcount = likeHelperService.getTotalCount(json);
    List<Like> list = null;
    if (totalcount > 0) {
        list = likeDao.getList(json);
    }
    Partion pt = new Partion(json, list, totalcount);
    logger.info("getList(获取微信点赞带分页数据-服务) 结束 ");
    return pt;
}
 
Example 8
/**
 * getList(获取代码生成方案带分页数据-服务)
 *
 * @param json
 * @return
 * @author rufei.cn
 */
public Partion getList(@RequestBody JSONObject json) {
    logger.info("getList(获取代码生成方案带分页数据-服务) 开始 json={}", json);
    if (json == null || json.size() < 1) {
        return null;
    }
    Partion pt = null;
    try {
        int totalcount = codeSchemeHelperService.getTotalCount(json);
        List<CodeScheme> list = null;
        if (totalcount > 0) {
            list = codeSchemeDao.getList(json);
        }
        pt = new Partion(json, list, totalcount);
    } catch (Exception e) {
        String msg = "getList(获取代码生成方案 异常 " + StringUtil.getExceptionMsg(e);
        logger.error(msg);
        String parms = null;
        if (json != null) {
            parms = json.toString();
        }
        sysCommonService.sendDingTalkMessage("base-service[getList]", parms, null, msg, this.getClass());
    }
    logger.info("getList(获取代码生成方案带分页数据-服务) 结束 ");
    return pt;
}
 
Example 9
Source Project: yue-library   File: DbDelete.java    License: Apache License 2.0 5 votes vote down vote up
private String deleteLogicSqlBuild(String tableName, JSONObject paramJson) {
	// 1. 参数验证
	paramValidate(tableName, paramJson);
	
	// 2. 生成SQL
	String[] conditions = new String[paramJson.size()];
	conditions = MapUtils.keyList(paramJson).toArray(conditions);
	paramJson.put(DbConstant.FIELD_DEFINITION_DELETE_TIME, System.currentTimeMillis());
	
	// 3. 返回结果
	return dialect.updateSqlBuild(tableName, paramJson, conditions, DbUpdateEnum.NORMAL);
}
 
Example 10
@Override
public List<SearchAliasReslut> parseData(JSONObject json) {
	
	List<SearchAliasReslut> list = new ArrayList<SearchAliasReslut>();
	
	if(json == null) {
		return list;
	}
	
	Iterator<Entry<String,Object>> ito = json.entrySet().iterator();
	while(ito.hasNext()) {
		Entry<String,Object> entry = ito.next();
		String index = entry.getKey();
		JSONObject obj = json.getJSONObject(index).getJSONObject("aliases");
		if(obj.size() == 0) {
			continue;
		}
		SearchAliasReslut sar = new SearchAliasReslut(index);
		List<AliasInfo> aliasList = new ArrayList<AliasInfo>();
		sar.setAliases(aliasList);
		Iterator<Entry<String,Object>> aliasIto = obj.entrySet().iterator();
		while(aliasIto.hasNext()) {
			Entry<String,Object> aliasEntry = aliasIto.next();
			aliasList.add(new AliasInfo(aliasEntry.getKey(), String.valueOf(aliasEntry.getValue())));
		}
		
		list.add(sar);
		
	}
	
	return list;
}
 
Example 11
Source Project: weex-uikit   File: WXDomModule.java    License: MIT License 5 votes vote down vote up
/**
 * Update attributes
 * @param ref
 * @param attr the expected attr
 */
public void updateAttrs(String ref, JSONObject attr) {
  if (TextUtils.isEmpty(ref) || attr == null || attr.size() < 1) {
    return;
  }
  Message msg = Message.obtain();
  WXDomTask task = new WXDomTask();
  task.instanceId = mWXSDKInstance.getInstanceId();
  task.args = new ArrayList<>();
  task.args.add(ref);
  task.args.add(attr);
  msg.what = WXDomHandler.MsgType.WX_DOM_UPDATE_ATTRS;
  msg.obj = task;
  WXSDKManager.getInstance().getWXDomManager().sendMessage(msg);
}
 
Example 12
Source Project: kafka-monitor   File: ZookeeperClient.java    License: Apache License 2.0 5 votes vote down vote up
private JSONObject loadZkConf(String path) {
    JSONObject zkConfig = JsonLoader.loadJSONFile(path);
    if (zkConfig.size() == 0) {
        zkConfig = defaultConfig();
    }
    return zkConfig;
}
 
Example 13
/**
 * 获取搜索结果,处理高亮词
 *
 * @param result
 * @param esPage
 */
public EsPartion getSearchResult(JestResult result, EsPage esPage) {
    EsPartion pt = null;
    int totalCount = result.getJsonObject().get("hits").getAsJsonObject().get("total").getAsInt();
    JsonArray asJsonArray = result.getJsonObject().get("hits").getAsJsonObject().get("hits").getAsJsonArray();
    List<JSONObject> list = new ArrayList<>();
    for (int i = 0; i < asJsonArray.size(); i++) {
        JsonElement jsonElement = asJsonArray.get(i);
        JsonObject source = jsonElement.getAsJsonObject().getAsJsonObject("_source").getAsJsonObject();
        JsonObject highlight = jsonElement.getAsJsonObject().getAsJsonObject("highlight");
        Set<Map.Entry<String, JsonElement>> entries = null;
        if (highlight != null) {
            entries = highlight.entrySet();
        }
        if (source == null || source.size() <= 0) {
            continue;
        }
        JSONObject jsonObject = JSONObject.parseObject(source.toString());
        if (jsonObject == null || jsonObject.size() <= 0) {
            continue;
        }
        jsonObject = addHightWord(entries, jsonObject);
        list.add(jsonObject);
    }
    pt = new EsPartion(esPage, list, totalCount);
    return pt;
}
 
Example 14
Source Project: sc-generator   File: DemoController.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/{id}/{table}/{primaryKey}", method = RequestMethod.GET)
@ResponseBody
public Object selectByPrimaryKey(@PathVariable(value = "id") Integer id,
                                 @PathVariable(value = "table") String table,
                                 @PathVariable(value = "primaryKey") String primaryKey) throws Exception {
    Datasource one = datasourceService.findOne(id);
    Connection connection = DriverManager.getConnection(one.getJdbcUrl(), one.getUsername(), one.getPassword());
    String column = TblUtil.getPrimaryKey(connection, table);
    String sql = "select * from `" + table + "` where `" + column + "`= '" + primaryKey + "'";
    if (TblUtil.isNumber(TblUtil.getColunmType(connection, table, column))) {
        sql = "select * from `" + table + "` where `" + column + "`= " + primaryKey;

    }

    logger.info(sql);

    PreparedStatement statement = connection.prepareStatement(sql);
    statement.execute();
    ResultSetMetaData metaData = statement.getMetaData();
    ResultSet statementResultSet = statement.getResultSet();
    JSONObject row = new JSONObject();

    while (statementResultSet.next()) {
        for (int i = 1; i < metaData.getColumnCount() + 1; i++) {
            String columnName = metaData.getColumnName(i);
            String fieldName = VelocityUtil.toHump(columnName);
            Object object = statementResultSet.getObject(columnName);
            row.put(fieldName, object);
        }
    }

    statementResultSet.close();
    statement.close();
    connection.close();
    return row.size() > 0 ? row : null;

}
 
Example 15
/**
 * getList(获取调度系统用户带分页数据-服务)
 *
 * @param json
 * @return
 * @author rufei.cn
 */
public Partion getList(@RequestBody JSONObject json) {
    logger.info("getList(获取调度系统用户带分页数据-服务) 开始 json={}", json);
    if (json == null || json.size() < 1) {
        return null;
    }
    Partion pt = null;
    try {
        int totalcount = jobUserHelperService.getTotalCount(json);
        List<JobUser> list = null;
        if (totalcount > 0) {
            list = jobUserDao.getList(json);
        }
        pt = new Partion(json, list, totalcount);
    } catch (Exception e) {
        String msg = "getList(获取调度系统用户 异常 " + StringUtil.getExceptionMsg(e);
        logger.error(msg);
        String parms = null;
        if (json != null) {
            parms = json.toString();
        }
        sysCommonService.sendDingTalkMessage("base-service[getList]", parms, null, msg, this.getClass());

    }
    logger.info("getList(获取调度系统用户带分页数据-服务) 结束 ");
    return pt;
}
 
Example 16
Source Project: ucar-weex-core   File: WXDomObject.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parse the jsonObject to {@link WXDomObject} recursively
 * @param map the original JSONObject
 */
public void parseFromJson(JSONObject map){
  if (map == null || map.size() <= 0) {
    return;
  }

  String type = (String) map.get("type");
  this.mType = type;
  this.mRef = (String) map.get("ref");
  Object style = map.get("style");
  if (style != null && style instanceof JSONObject) {
    WXStyle styles = new WXStyle();
    styles.putAll((JSONObject) style,false);
    this.mStyles = styles;
  }
  Object attr = map.get("attr");
  if (attr != null && attr instanceof JSONObject) {
    WXAttr attrs = new WXAttr((JSONObject) attr);
    //WXJsonUtils.putAll(attrs, (JSONObject) attr);
    this.mAttributes = attrs;
  }
  Object event = map.get("event");
  if (event != null && event instanceof JSONArray) {
    WXEvent events = new WXEvent();
    JSONArray eventArray = (JSONArray) event;
    int count = eventArray.size();
    for (int i = 0; i < count; ++i) {
      events.add(eventArray.getString(i));
    }
    this.mEvents = events;
  }

}
 
Example 17
Source Project: rainbow   File: HttpUtilTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
    public void HttpGetFilterTest() {
        SqlParser parser = new SqlParser();
        Query q = null;
        Object o = new Object();
        JSONArray jsonArray = null;

        int num = 0, cou = 0;
        while (true) {
            o = HttpUtil.HttpGet(Settings.PRESTO_QUERY);
            jsonArray = JSON.parseArray(o.toString());

            String queryId = null;
            String query = null;
            for (int i = count; i < jsonArray.size(); i++) {
                System.out.println("Loop Times: " + num);
                JSONObject jsonObject = (JSONObject) jsonArray.get(i);
                if (jsonObject.size() == 8) {
                    queryId = jsonObject.get("queryId").toString();
                    query = jsonObject.get("query").toString();
//                    System.out.println(queryId + "\t" + i + "\t" + query);
                    // Parser
                    try {
                        q = (Query) parser.createStatement(query);
                    } catch (Exception e) {
                        ExceptionHandler.Instance().log(ExceptionType.ERROR, "query error", e);
                    }
//                System.out.println(q.toString());
                    QuerySpecification queryBody = (QuerySpecification) q.getQueryBody();
                    // get columns
                    List<SelectItem> selectItemList = queryBody.getSelect().getSelectItems();
                    for (SelectItem column : selectItemList) {
                        System.out.println(column.toString());
                    }
                    // tableName
                    Table t = (Table) queryBody.getFrom().get();
                    System.out.println(t.getName());
                    if (t.getName().equals("text")) {
                        System.out.println("Text visit: " + cou++);
                    }
                }
            }
            // update count
            count = jsonArray.size();
            num++;
            o = new Object();
        }
    }
 
Example 18
Source Project: tephra   File: PptxReaderImpl.java    License: MIT License 4 votes vote down vote up
private void add(JSONArray shapes, JSONObject shape) {
    if (shape.isEmpty() || (shape.size() == 1 && shape.containsKey("anchor")))
        return;

    shapes.add(shape);
}
 
Example 19
public Object tryConvertToObject(String json, Class type, OAuth2Response response) {
    if (json.startsWith("{")) {
        if (ResponseMessage.class.isAssignableFrom(type)) {
            return JSON.parseObject(json, type);
        }
        JSONObject message = JSON.parseObject(json, Feature.DisableFieldSmartMatch);
        //判断是否响应的为ResponseMessage
        if (message.size() <= responseMessageFieldSize
                && message.get("status") != null && message.get("timestamp") != null) {

            Integer status = message.getInteger("status");
            if (status != 200) {
                throw new BusinessException(message.getString("message"), status);
            }
            Object data = message.get("result");
            if (data == null) {
                return null;
            }
            //返回的是对象
            if (data instanceof JSONObject) {
                if (type == Authentication.class) {
                    return autzParser.apply(data);
                }
                return ((JSONObject) data).toJavaObject(type);
            }
            //返回的是集合
            if (data instanceof JSONArray) {
                if (type == Authentication.class) {
                    return ((JSONArray) data).stream().map(autzParser).collect(Collectors.toList());
                }
                return ((JSONArray) data).toJavaList(type);
            }
            //return data;
            return message.getObject("result", type);
        }
        if (springMvcErrorResponseKeys.containsAll(message.keySet())) {
            throw new OAuth2RequestException(ErrorType.SERVICE_ERROR, response);
        }
        return message.toJavaObject(type);
    } else if (json.startsWith("[")) {
        if (type == Authentication.class) {
            return (JSON.parseArray(json)).stream().map(autzParser).collect(Collectors.toList());
        }
        return JSON.parseArray(json, type);
    }
    return null;
}
 
Example 20
Source Project: springBoot-study   File: MyTools.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 判断JSONObject类型的数据是否为空 null,[] 为true
 * 
 * @return boolean
 */
public static boolean isEmpty(JSONObject json) {
	return (null == json || json.size() == 0);
}