本文整理汇总了Java中com.alibaba.fastjson.JSONObject.get方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.get方法的具体用法?Java JSONObject.get怎么用?Java JSONObject.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.JSONObject
的用法示例。
在下文中一共展示了JSONObject.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserInfo
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public static String getUserInfo(String code, int agentid) {
String urlStr = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token="+WeiXinCompanyUtils.getToken()+
// "&code="+code+"&agentid="+CommonUtils.WX_QY_AGENT_TEST;
"&code="+code+"&agentid="+agentid;
try {
URL url = new URL(urlStr);
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.setDoInput(true);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String s = null;
StringBuilder sb = new StringBuilder();
while ((s=reader.readLine()) != null) {
sb.append(s);
}
JSONObject jsonObject = JSON.parseObject(sb.toString());
if(jsonObject.get("UserId") !=null){
return jsonObject.get("UserId").toString();
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例2: convert
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Override
public Object convert(Object obj, Field field, Map<String, Object> excelRecordMap) {
logger.trace("field: " + field.getName() +
", obj: " + obj +
" run ValueMapConvertor");
String jsonStr = field.getAnnotation(ValueMap.class).value();
if (StringUtils.isBlank(jsonStr))
throw new RuntimeException("field注解ValueMap值为空,filed:" + field.getName());
logger.debug(jsonStr);
JSONObject json;
try {
json = JSONObject.parseObject(jsonStr);
} catch (Exception e) {
throw new RuntimeException("field注解ValueMap值不是有效json,filed:" + field.getName(), e);
}
if (obj != null) {
obj = json.get(obj.toString());
}
return obj;
}
示例3: mergeJSONObject
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
private static void mergeJSONObject(JSONObject target, JSONObject from, ArrayMergeStrategy arrayMergeStrategy){
for (Map.Entry<String, Object> field : from.entrySet()) {
if (target.containsKey(field.getKey())) {
Object targetFieldValue = target.get(field.getKey());
Object fromFieldValue = field.getValue();
if ((targetFieldValue instanceof JSONObject) && (fromFieldValue instanceof JSONObject)) {
// 都是 JSON 对象,进行深度合并;
mergeJSONObject((JSONObject) targetFieldValue, (JSONObject) fromFieldValue, arrayMergeStrategy);
} else if ((targetFieldValue instanceof JSONArray) && (fromFieldValue instanceof JSONArray)) {
// 都是 JSON 数组,进行数组合并;
mergeJSONArray((JSONArray) targetFieldValue, (JSONArray) fromFieldValue, arrayMergeStrategy);
} else {
// 类型不同,直接替换;
target.put(field.getKey(), field.getValue());
}
} else {
target.put(field.getKey(), field.getValue());
}
}
}
示例4: toMultiNameValues
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public static MultiNameValues toMultiNameValues(JSONArray jsonArray)
{
JSONObject jsonObject = jsonArray.getJSONObject(0);
String[] names = jsonObject.keySet().toArray(new String[0]);
MultiNameValues multiNameValues = new MultiNameValues();
multiNameValues.names(names);
for (int i = 0; i < jsonArray.size(); i++)
{
jsonObject = jsonArray.getJSONObject(i);
Object[] values = new Object[names.length];
multiNameValues.addValues(values);
for (int k = 0; k < names.length; k++)
{
values[k] = jsonObject.get(names[k]);
}
}
return multiNameValues;
}
示例5: getResult
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 获取执行结果
*
* @author gaoxianglong
*
* @param httpResponse
*
* @param entity
*
* @exception Exception
*
* @return OutParamBean
*/
public default OutParamBO getResult(CloseableHttpResponse httpResponse, HttpEntity entity) {
OutParamBO outParamBO = new OutParamBO();
int httpCode = 200;
if (httpCode == httpResponse.getStatusLine().getStatusCode()) {
outParamBO.setErrorCode(httpCode);
try {
JSONObject obj = JSONObject.parseObject(EntityUtils.toString(entity, CHAR_SET));
Object errorCode = obj.get("errorCode");
Object data = obj.get("data");
if (null != errorCode) {
outParamBO.setErrorCode(Integer.parseInt(errorCode.toString()));
}
if (null != data) {
outParamBO.setData(data.toString());
}
} catch (Exception e) {
log.debug("返回的并非是JSON");
}
}
return outParamBO;
}
示例6: checkJsonKeysNotNull
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* @Title: checkJsonKeysNotNull
* @Description: TODO(检查Json传入Key值是否为空)
* @param ReturnUtil returnUtil
* @param Json 保存参数的Json
* @param str 必填参数key值
* @return boolean 返回类型 true 参数通过 false 参数错误
*/
public static boolean checkJsonKeysNotNull(ReturnUtil returnUtil,JSONObject json,String... Keys){
if(json==null){
returnUtil.addError("无传入参数!请修改后重试!");
return false;
}
if(Keys.length==0){
Keys = new String[json.keySet().size()];
Keys = json.keySet().toArray(Keys);
}
for (String key : Keys) {
if(json.get(key)==null){
returnUtil.addError("缺少参数“"+key+"”!请修改后重试!");
return false;
}else if(isNull(json.get(key))){
returnUtil.addError("参数“"+key+"”内容为空!请修改后重试!");
return false;
}
}
return true;
}
示例7: parseInner
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* Parse the jsonObject to {@link WXDomObject} recursively
* @param map the original JSONObject
* @return Dom Object corresponding to the JSONObject.
*/
private @Nullable WXDomObject parseInner(JSONObject map) {
if (map == null || map.size() <= 0) {
return null;
}
String type = (String) map.get(TYPE);
WXDomObject domObject = WXDomObjectFactory.newInstance(type);
if(domObject == null){
return null;
}
domObject.parseFromJson(map);
Object children = map.get(CHILDREN);
if (children != null && children instanceof JSONArray) {
JSONArray childrenArray = (JSONArray) children;
int count = childrenArray.size();
for (int i = 0; i < count; ++i) {
domObject.add(parseInner(childrenArray.getJSONObject(i)),-1);
}
}
return domObject;
}
示例8: addMaterialEver
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 上传图片到微信服务器(本接口所上传的图片不占用公众号的素材库中图片数量的5000个的限制。图片仅支持jpg/png格式,大小必须在1MB以下)
*/
public JSONObject addMaterialEver(String appid, String secret, File file) throws Exception {
try {
System.out.println("开始上传图文消息内的图片---------------------");
//开始获取证书
String accessToken = tokenUtil.getToken();
if (Strings.isNullOrEmpty(accessToken)) {
logger.info("accessToken is null");
return null;
}
//上传图片素材
String path = "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=" + accessToken;
String result = connectHttpsByPost(path, file);
result = result.replaceAll("[\\\\]", "");
System.out.println("result:" + result);
JSONObject resultJSON = JSONObject.parseObject(result);
if (resultJSON != null) {
if (resultJSON.get("url") != null) {
System.out.println("上传图文消息内的图片成功");
return resultJSON;
} else {
System.out.println("上传图文消息内的图片失败");
}
}
return null;
} catch (Exception e) {
logger.error("程序异常", e);
throw e;
} finally {
System.out.println("结束上传图文消息内的图片---------------------");
}
}
示例9: getNumberValueNoRule
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
protected Number getNumberValueNoRule(Field field, JSONObject content)
{
String fieldName = field.getName();
Number value = (Number) content.get(fieldName);
value = (null == value) ? (Number) field.getDefaultValue() : value;
Assert.notNull(value, "the protocol 's field[ " + fieldName + "] not allow null,please set default value or set current message value");
return value;
}
示例10: callDomMethod
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public void callDomMethod(JSONObject task) {
if (task == null) {
return;
}
String method = (String) task.get(WXBridgeManager.METHOD);
JSONArray args = (JSONArray) task.get(WXBridgeManager.ARGS);
callDomMethod(method,args);
}
示例11: getExtra
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
private static Object getExtra(JSONObject jsonObject)
{
Object result = null;
if (jsonObject.containsKey(EXTRA_FIELD))
{
result = jsonObject.get(EXTRA_FIELD);
if (result instanceof String && ("true".equals(result) || "false".equals(result)))
{
result = Boolean.parseBoolean(result.toString());
}
}
return result;
}
示例12: getArray
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* key = KEY_ARRAY
* @param object
* @param className
* @return
*/
public static JSONArray getArray(JSONObject object, String key, String className) {
Object obj = object == null ? null : object.get(replaceArray(key));
if (obj == null) {
return null;
}
return obj instanceof JSONArray ? (JSONArray) obj : toArray((JSONObject) obj, className);
}
示例13: onMessage
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type)
throws IOException {
if (type != WebSocket.PayloadType.TEXT) {
WXLogUtils.w(
"Websocket received unexpected message with payload of type "
+ type);
return;
}
for (JSDebuggerCallback callback : mCallbacks.values()) {
callback.onMessage(payload, type);
}
String message = null;
try {
message = payload.readUtf8();
JSONObject jsonObject = JSONObject.parseObject(message);
Object name = jsonObject.get("method");
Object value = jsonObject.get("arguments");
if (name == null || value == null) {
return;
}
if (TextUtils.equals(name.toString(), "setLogLevel")) {
JSONArray jsonArray = JSONObject.parseArray(value.toString());
String level = jsonArray.get(0).toString();
WXEnvironment.sLogLevel = LogLevel.valueOf(level.toUpperCase());
WXLogUtils.v("into--[onMessage]setLogLevel");
}
} catch (Exception e) {
} finally {
payload.close();
}
}
示例14: mongodb2greenplum
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* @decription 数据同步(MongoDB-->Greenplum)
* @author yi.zhang
* @time 2017年8月4日 下午5:26:59
* @param source 数据源
* @param target 目标库
* @param mapper 表映射
* @param filter_columns 字段过滤
*/
protected void mongodb2greenplum(Config source,Config target,Map<String,String> mapper,List<String> filter_columns){
if(source==null||target==null){
return;
}
MongoDBFactory factory = new MongoDBFactory();
factory.init(source.getServers(), source.getDatabase(), source.getSchema(), 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;
}
GreenplumFactory tfactory = new GreenplumFactory();
tfactory.init(target.getServers(), target.getDatabase(), target.getSchema(), target.getUsername(), target.getPassword(), true, 100, 10);
List<String> stables = factory.queryTables();
List<String> ttables = tfactory.queryTables();
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;
}
List<?> datas = factory.executeQuery(stable, null, 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);
}
String sql = "insert into "+ttable+"("+StringUtils.join(tdata.keySet(), ",")+")values("+StringUtils.join(tdata.values(), ",")+")";
tfactory.executeUpdate(sql);
}
}
}
示例15: 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);
}
}
}