當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONObject.keySet方法代碼示例

本文整理匯總了Java中com.alibaba.fastjson.JSONObject.keySet方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.keySet方法的具體用法?Java JSONObject.keySet怎麽用?Java JSONObject.keySet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.alibaba.fastjson.JSONObject的用法示例。


在下文中一共展示了JSONObject.keySet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toMap

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
 * JSONObject轉為map
 * @param object json對象
 * @return 轉化後的Map
 */
public static Map<String, Object> toMap(JSONObject object){
    Map<String, Object> map = new HashMap<String, Object>();

    for (String key : object.keySet()) {
        Object value = object.get(key);
        if(value instanceof JSONArray) {
            value = toList((JSONArray) value);
        }else if(value instanceof JSONObject) {
            value = toMap((JSONObject) value);
        }
        map.put(key, value);
    }

    return map;
}
 
開發者ID:alamby,項目名稱:upgradeToy,代碼行數:21,代碼來源:ParseEventMap.java

示例2: toJoinForSign

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
 * 連接字符串
 *
 * @param object  對象
 * @param charset 字符集
 * @param withQuota 是否加引號
 * @param encode  是否編碼
 * @return str
 */
public static String toJoinForSign(Object object, Charset charset, boolean encode, boolean withQuota) {
    Map<String, String> map = new HashMap<String, String>();
    JSONObject obj = null;
    if (object instanceof String) {
        obj = JSONObject.parseObject((String) object);
    } else {
        obj = ListSuffixResultSerializer.serializeToJSON(object);
    }
    for (String key : obj.keySet()) {
        String value = obj.getString(key);
        if (Strings.isNullOrEmpty(value)) {
            continue;
        }
        map.put(key, value);
    }
    return toJoinForSign(map, charset, encode, withQuota);
}
 
開發者ID:24solar,項目名稱:pay4j,代碼行數:27,代碼來源:StringUtil.java

示例3: toJoinString

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
 * 連接字符串
 *
 * @param object    對象
 * @param withQuota 是否加引號
 * @return str
 */
public static String toJoinString(Object object, boolean withQuota) {
    Map<String, String> map = new HashMap<String, String>();
    JSONObject obj = null;
    if (object instanceof String) {
        obj = JSONObject.parseObject((String) object);
    } else {
        obj = ListSuffixResultSerializer.serializeToJSON(object);
    }
    for (String key : obj.keySet()) {
        String value = obj.getString(key);
        if (Strings.isNullOrEmpty(value)) {
            continue;
        }
        map.put(key, value);
    }
    return toJoinString(map, withQuota);
}
 
開發者ID:24solar,項目名稱:pay4j,代碼行數:25,代碼來源:StringUtil.java

示例4: extractHeaders

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private void extractHeaders(JSONObject headers, Options.Builder builder, String type){
    if(headers != null){
        for (String key : headers.keySet()) {
            builder.putHeader(key, headers.getString(key));
        }
    }
    builder.putHeader("platform", "android");
    switch (type) {
        case "text":
            builder.putHeader("Content-Type", "text/plain");
            break;
        case "json":
            builder.putHeader("Content-Type", "application/json");
            break;
        case "jsonp":
            builder.putHeader("Content-Type", "text/javascript");
            break;
    }
}
 
開發者ID:natjs,項目名稱:nat-network-stream,代碼行數:20,代碼來源:StreamModule.java

示例5: exports

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void exports(JSONObject font, Double splitAtX, Double splitAtY, Double err) {
    font.put("CFF_", null);
    JSONObject glyf = font.getJSONObject("glyf");
    for (String k : glyf.keySet()) {
        JSONObject g = glyf.getJSONObject(k);
        Contour[][] contours = g.getObject("contours", Contour[][].class);
        if (contours != null) {
            contours = c2qContours(contours, splitAtX, splitAtY, err);
        }
        g.put("contours", contours);
        g.put("stemH", null);
        g.put("stemV", null);
        g.put("hintMasks", null);
        g.put("contourMasks", null);
    }
    JSONObject maxp = font.getJSONObject("maxp");
    maxp.put("version", 1.0);
}
 
開發者ID:icaoweiwei,項目名稱:otf2ttf,代碼行數:19,代碼來源:CTQ.java

示例6: sortDesc

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static JSONObject sortDesc(JSONObject json){
    JSONObject newJson = new JSONObject(true);
    LinkedList<String> setSort = new LinkedList<String>(json.keySet());        
    Comparator<String> setComp = Collections.reverseOrder();
    Collections.sort(setSort,setComp);
    for(String key : setSort)
        newJson.put(key, json.get(key));
       return newJson;
}
 
開發者ID:zhiqiang94,項目名稱:BasicsProject,代碼行數:10,代碼來源:JsonSortUtil.java

示例7: format

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**將Table[]:{0:{Table:{}}, 1:{Table:{}}...} 轉化為 tableList:[{}, {}]
 * @param target
 * @param response
 * @return
 */
public static JSONObject format(final JSONObject response) {
    Log.i(TAG, "format  response = \n" + JSON.toJSONString(response));
    if (response == null || response.isEmpty()) {
        Log.i(TAG, "format  response == null || response.isEmpty() >> return response;");
        return response;
    }
    JSONObject transferredObject = new JSONObject(true);

    Set<String> set = response.keySet();
    if (set != null) {
        
        Object value;
        String arrayKey;
        for (String key : set) {
            value = response.get(key);
            
            if (value instanceof JSONArray) {//轉化JSONArray內部的APIJSON Array
                transferredObject.put(getSimpleName(key), format((JSONArray) value));
            } else if (value instanceof JSONObject) {//APIJSON Array轉為常規JSONArray
                if (isArrayKey(key)) {//APIJSON Array轉為常規JSONArray
                    arrayKey = key.substring(0, key.indexOf(KEY_ARRAY));
                    transferredObject.put(getArrayKey(getSimpleName(arrayKey))
                            , format(toArray((JSONObject) value, arrayKey)));//需要將name:alias傳至toArray
                } else {//常規JSONObject,往下一級提取
                    transferredObject.put(getSimpleName(key), format((JSONObject) value));
                }
            } else {//其它Object,直接填充
                transferredObject.put(getSimpleName(key), value);
            }
        }
    }

    Log.i(TAG, "format  return transferredObject = " + JSON.toJSONString(transferredObject));
    return transferredObject;
}
 
開發者ID:TommyLemon,項目名稱:APIJSON-Android-RxJava,代碼行數:41,代碼來源:JSONResponse.java

示例8: initRemoteProps

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
 * 初始化遠程配置信息
 */
private void initRemoteProps() {
    String jsonString = httpGet(url+"/"+name);

    if (StringUtils.isBlank(jsonString)) {
        LogKit.error("can not get remote config info,plase check url : " + url);
        return;
    }

    JSONObject jsonObject = null;
    try {
        jsonObject = JSON.parseObject(jsonString);
    } catch (Throwable ex) {
        LogKit.error("can not parse json : \n" + jsonString + "\n\nfrom url : " + url, ex);
        return;
    }

    //先清空本地數據,initRemoteProps 可能被多次調用
    remoteProperties.clear();
    remotePropInfoMap.clear();

    for (String key : jsonObject.keySet()) {
        JSONObject propInfoObject = jsonObject.getJSONObject(key);
        String version = propInfoObject.getString("version");
        JSONObject propertiesObject = propInfoObject.getJSONObject("properties");

        Properties properties = new Properties();
        for (String propertieKey : propertiesObject.keySet()) {
            properties.put(propertieKey, propertiesObject.getString(propertieKey));
            remoteProperties.put(propertieKey, propertiesObject.getString(propertieKey));
        }
        remotePropInfoMap.put(key, new PropInfoMap.PropInfo(version, properties));
    }
}
 
開發者ID:yangfuhai,項目名稱:jboot,代碼行數:37,代碼來源:ConfigRemoteReader.java

示例9: extractHeaders

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private void extractHeaders(JSONObject headers, Options.Builder builder){
  //set user-agent
  String UA = WXHttpUtil.assembleUserAgent(WXEnvironment.getApplication(),WXEnvironment.getConfig());
  if(headers != null){
    for (String key : headers.keySet()) {
      if (key.equals(KEY_USER_AGENT)) {
        UA = headers.getString(key);
        continue;
      }
      builder.putHeader(key, headers.getString(key));
    }
  }
  builder.putHeader(KEY_USER_AGENT,UA);
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:15,代碼來源:WXStreamModule.java

示例10: jsonToXCO

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
protected XCO jsonToXCO(JSONObject json) {
    XCO x = new XCO();
    for (String k : json.keySet()) {
        Object v = json.get(k);
        if (v instanceof JSONArray) {
            x.setObjectValue(k, ((JSONArray) v).toArray());
        } else if (v instanceof JSONObject) {
            x.setXCOValue(k, jsonToXCO((JSONObject) v));
        } else {
            x.setObjectValue(k, v);
        }
    }
    return x;
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:15,代碼來源:FastJsonConverter.java

示例11: sortAsc

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static JSONObject sortAsc(JSONObject json){
    JSONObject newJson = new JSONObject(true);
    LinkedList<String> setSort = new LinkedList<String>(json.keySet());        
       Collections.sort(setSort);
       for(String key : setSort)
       	newJson.put(key, json.get(key));
       return newJson;
}
 
開發者ID:zhiqiang94,項目名稱:BasicsProject,代碼行數:9,代碼來源:JsonSortUtil.java

示例12: jsonToMap

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
protected Map<String, Object> jsonToMap(JSONObject json) {
    Map<String, Object> map = new HashMap<String, Object>();
    for (String k : json.keySet()) {
        Object v = json.get(k);
        if (v instanceof JSONArray) {
            map.put(k, arrayToMap((JSONArray) v));
        } else if (v instanceof JSONObject) {
            map.put(k, jsonToMap((JSONObject) v));
        } else {
            map.put(k, v);
        }
    }
    return map;
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:15,代碼來源:FastJsonConverter.java

示例13: toArray

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
 * array.set(index, isContainer ? value : value.getJSONObject(className));
 * @param arrayObject
 * @param className className.isEmpty() == false && value.containsKey(className) >> isContainer = true;
 * @return
 */
public static JSONArray toArray(JSONObject arrayObject, String className) {
    Set<String> set = arrayObject == null ? null : arrayObject.keySet();
    if (set == null || set.isEmpty()) {
        return null;
    }

    // [{...},{...},...]
    String parentString = StringUtil.getTrimedString(JSON.toJSONString(arrayObject));
    if (parentString.isEmpty()) {
        return null;
    }
    if (parentString.startsWith("[")) {
        if (parentString.endsWith("]") == false) {
            parentString += "]";
        }
        return JSON.parseArray(parentString);
    }

    //{"0":{Table:{...}}, "1":{Table:{...}}...}

    className = StringUtil.getTrimedString(className);
    boolean isContainer = true;

    JSONArray array = new JSONArray(set.size());
    JSONObject value;
    boolean isFirst = true;
    int index;
    for (String key : set) {//0, 1, 2,...
        value = StringUtil.isNumer(key) == false ? null : arrayObject.getJSONObject(key);// Table:{}
        if (value != null) {
            try {
                index = Integer.valueOf(0 + key);
                if (isFirst && className.isEmpty() == false && value.containsKey(className)) {// 判斷是否需要提取table
                    isContainer = false;
                }
                array.set(index, isContainer ? value : value.getJSONObject(className));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        isFirst = false;
    }
    return array;
}
 
開發者ID:TommyLemon,項目名稱:APIJSON-Android-RxJava,代碼行數:51,代碼來源:JSONResponse.java

示例14: cassandra2cassandra

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
     * @decription 數據同步(Cassandra-->Cassandra)
     * @author yi.zhang
     * @time 2017年8月4日 下午5:26:59
     * @param source	數據源
     * @param target	目標庫
     * @param mapper	表映射
     * @param filter_columns	字段過濾
     */
    protected void cassandra2cassandra(Config source,Config target,Map<String,String> mapper,List<String> filter_columns){
        if(source==null||target==null){
            return;
        }
        CassandraFactory factory = new CassandraFactory();
        factory.init(source.getServers(), source.getKeyspace(), source.getUsername(), source.getPassword());
        Map<String,String> mapping = new HashMap<String,String>();
        if(mapper==null||mapper.size()==0){
            List<String> tables = factory.queryTables();
            for (String table : tables) {
                mapping.put(table, table);
            }
        }else{
            mapping = mapper;
        }
        CassandraFactory tfactory = new CassandraFactory();
        tfactory.init(target.getServers(), target.getKeyspace(), target.getUsername(), target.getPassword());
        for(String stable : mapping.keySet()){
            String ttable = mapping.get(stable);
//			if(!(stables.contains(stable)&&ttables.contains(ttable))){
//				System.out.println("--數據表["+stable+"]或目標表["+ttable+"]不存在--");
//				continue;
//			}
            Map<String,String> reflect = new LinkedHashMap<String,String>();
            Map<String, String> scolumns = factory.queryColumns(stable);
            Map<String, String> tcolumns = tfactory.queryColumns(ttable);
            if(scolumns==null||scolumns.isEmpty()||tcolumns==null||tcolumns.isEmpty()){
                System.out.println("--數據表["+stable+"]或目標表["+ttable+"]無合適字段--");
                continue;
            }
            for(String scolumn:scolumns.keySet()){
                String s_column = scolumn.trim().toLowerCase().replaceAll("(_+?|-+?)", "");
                if(filter_columns!=null&&(filter_columns.contains(scolumn)||filter_columns.contains(s_column))){
                    continue;
                }
                for(String tcolumn:tcolumns.keySet()){
                    String t_column = tcolumn.trim().toLowerCase().replaceAll("(_+?|-+?)", "");
                    if(filter_columns!=null&&(filter_columns.contains(tcolumn)||filter_columns.contains(t_column))){
                        continue;
                    }
                    if(scolumn.equalsIgnoreCase(tcolumn)||scolumn.equalsIgnoreCase(t_column)||s_column.equalsIgnoreCase(tcolumn)||s_column.equalsIgnoreCase(t_column)){
                        reflect.put(scolumn, tcolumn);
                    }
                }
            }
            if(reflect.isEmpty()){
                System.out.println("--數據表["+stable+"]或目標表["+ttable+"]無對應字段--");
                continue;
            }
            String cql = "select "+StringUtils.join(reflect.keySet(), ",")+" from "+stable;
            List<?> datas = factory.executeQuery(cql, null);
            System.out.println("--目標表["+stable+"]數據量:"+datas.size());
            for (Object data : datas) {
                Map<String,Object> tdata = new LinkedHashMap<String,Object>();
                JSONObject json = (JSONObject)data;
                for(String key:json.keySet()){
                    Object value = json.get(key);
                    if(value instanceof Date){
                        value = DateUtil.formatDateTimeStr((Date)value);
                    }
                    if(value instanceof String){
                        value = "\""+json.getString(key)+"\"";
                    }
                    tdata.replace(reflect.get(key), value);
                }
//				tfactory.save(tdata);
                String sql = "insert into "+ttable+"("+StringUtils.join(tdata.keySet(), ",")+")values("+StringUtils.join(tdata.values(), ",")+")";
                tfactory.executeUpdate(sql);
            }
        }
    }
 
開發者ID:dev-share,項目名稱:database-transform-tool,代碼行數:81,代碼來源:ManageTable.java

示例15: cassandra2mongodb

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
     * @decription 數據同步(Cassandra-->MongoDB)
     * @author yi.zhang
     * @time 2017年8月4日 下午5:26:59
     * @param source	數據源
     * @param target	目標庫
     * @param mapper	表映射
     * @param filter_columns	字段過濾
     */
    protected void cassandra2mongodb(Config source,Config target,Map<String,String> mapper,List<String> filter_columns){
        if(source==null||target==null){
            return;
        }
        CassandraFactory factory = new CassandraFactory();
        factory.init(source.getServers(), source.getKeyspace(), source.getUsername(), source.getPassword());
        Map<String,String> mapping = new HashMap<String,String>();
        if(mapper==null||mapper.size()==0){
            List<String> tables = factory.queryTables();
            for (String table : tables) {
                mapping.put(table, table);
            }
        }else{
            mapping = mapper;
        }
        MongoDBFactory tfactory = new MongoDBFactory();
        tfactory.init(target.getServers(), target.getDatabase(), target.getSchema(), target.getUsername(), target.getPassword());
//		List<String> stables = factory.queryTables();
        List<String> ttables = tfactory.queryTables();
        for(String stable : mapping.keySet()){
            String ttable = mapping.get(stable);
            if(!(ttables.contains(ttable))){
                System.out.println("--數據表["+stable+"]或目標表["+ttable+"]不存在--");
                continue;
            }
            Map<String,String> reflect = new LinkedHashMap<String,String>();
            Map<String, String> scolumns = factory.queryColumns(stable);
            Map<String, String> tcolumns = tfactory.queryColumns(ttable);
            if(scolumns==null||scolumns.isEmpty()||tcolumns==null||tcolumns.isEmpty()){
                System.out.println("--數據表["+stable+"]或目標表["+ttable+"]無合適字段--");
                continue;
            }
            for(String scolumn:scolumns.keySet()){
                String s_column = scolumn.trim().toLowerCase().replaceAll("(_+?|-+?)", "");
                if(filter_columns!=null&&(filter_columns.contains(scolumn)||filter_columns.contains(s_column))){
                    continue;
                }
                for(String tcolumn:tcolumns.keySet()){
                    String t_column = tcolumn.trim().toLowerCase().replaceAll("(_+?|-+?)", "");
                    if(filter_columns!=null&&(filter_columns.contains(tcolumn)||filter_columns.contains(t_column))){
                        continue;
                    }
                    if(scolumn.equalsIgnoreCase(tcolumn)||scolumn.equalsIgnoreCase(t_column)||s_column.equalsIgnoreCase(tcolumn)||s_column.equalsIgnoreCase(t_column)){
                        reflect.put(scolumn, tcolumn);
                    }
                }
            }
            if(reflect.isEmpty()){
                System.out.println("--數據表["+stable+"]或目標表["+ttable+"]無對應字段--");
                continue;
            }
            String cql = "select "+StringUtils.join(reflect.keySet(), ",")+" from "+stable;
            List<?> datas = factory.executeQuery(cql, null);
            System.out.println("--目標表["+stable+"]數據量:"+datas.size());
            for (Object data : datas) {
                Map<String,Object> tdata = new LinkedHashMap<String,Object>();
                JSONObject json = (JSONObject)data;
                for(String key:json.keySet()){
                    Object value = json.get(key);
                    if(!key.matches("(\\w+)")){
                        continue;
                    }
                    tdata.replace(reflect.get(key), value);
                }
                tfactory.save(ttable, tdata);
            }
        }
    }
 
開發者ID:dev-share,項目名稱:database-transform-tool,代碼行數:78,代碼來源:ManageTable.java


注:本文中的com.alibaba.fastjson.JSONObject.keySet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。