本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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));
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
}