/** * Make a JSON text of this JSONArray. For compactness, no * unnecessary whitespace is added. If it is not possible to produce a * syntactically correct JSON text then null will be returned instead. This * could occur if the array contains an invalid number. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return a printable, displayable, transmittable * representation of the array. */ @Override public String toString() { try { return _inner.toString(); } catch (Exception e) { return null; } }
private List<LBSModel> toListModel(JSONObject response) { int status = response.getInteger("status"); if (status != 0) { FailToEvent(); return null; } JSONArray dataJSON = response.getJSONArray("contents"); List<LBSModel> data = new ArrayList<>(); if (dataJSON != null && !TextUtils.isEmpty(dataJSON.toString())) { List<LBSModel> list = JSON.parseArray(dataJSON.toString(), LBSModel.class); data.addAll(list); } return data; }
/** * 创建报文体信息 * * @param objs * @return */ public static String createSvcCont(Object... objs) { JSONArray svcContArray = new JSONArray(); for (int objIndex = 0; objIndex < objs.length; objIndex++) { svcContArray.add(JSONObject.parseObject(JSONObject.toJSONString(objs[objIndex]))); } return svcContArray.toString(); }
public static String convertResourceToString(List<Map<String, String>> list) { String resource = "[]"; if (list != null && list.size() > 0) { JSONArray resArray = new JSONArray(); for (Map<String, String> map : list) { JSONObject o = new JSONObject(); for (String key : map.keySet()) { o.put(key, map.get(key)); } resArray.add(o); } resource = resArray.toString(); } return resource; } }
@Override public List<ZabbixResult> acqResults(JSONObject response) { if (response == null) return null; try { JSONArray result = response.getJSONArray("result"); if (result == null) return null; //System.err.println(result); //ZabbixResult zabbixRsult = gson.fromJson(result.toString(), ZabbixResult.class); List<ZabbixResult> results = gson.fromJson(result.toString(), new TypeToken<List<ZabbixResult>>() { }.getType()); return results; } catch (Exception e) { e.printStackTrace(); logger.error("zabbix result错误:" + response.toJSONString()); } return null; }
public static String convertProcessorToList(List<Processor> list) { JSONArray preArray = new JSONArray(); for (Processor p : list) { JSONObject o = new JSONObject(); o.put("id", p.getId()); o.put("config", p.getConfig()); preArray.add(o); } return preArray.toString(); }
return array.toString();
/** * @param access_token OAuth授权必填参数 * @param uids 需要获取数据的用户UID,多个之间用逗号分隔 * * 批量获取用户的粉丝数、关注数、微博数接口 */ public static JSONArray getCounts(String access_token,String uids){ JSONArray j=null; try { logger.info("根据用户ID获取用户信息的参数为:access_token:"+access_token+" 需要查询的用户ID:"+uids); //验证请求参数 WeiboUsersUtil.getCountsParmValidate(access_token, uids); String requestUrl = WeiboUsersUtil.getCountsUrl(counts_url, access_token, uids); logger.info("根据用户ID获取用户信息的路径为:"+requestUrl); j = HttpUtil.httpRequestArr(requestUrl, "GET", null); if(j!=null){ logger.info("根据用户ID获取用户信息的结果为:"+j.toString()); }else{ logger.info("根据用户ID获取用户信息的结果为:null"); } }catch(BusinessException e) { logger.info(e.getMessage()); } catch (Exception e) { e.printStackTrace(); } return j; }
/** * @param access_token OAuth授权必填参数 * @param ids 需要获取数据的微博ID,多个之间用逗号分隔 * 批量获取指定微博的转发数评论数接口 */ public static JSONArray getCount(String access_token,String ids){ JSONArray j=null; try { logger.info("批量获取指定微博的转发数评论数的参数为:access_token:"+access_token+" 微博ID:"+ids); //验证请求参数 WeiboStatusesUtil.getCountParmValidate(access_token,ids); String requestUrl = WeiboStatusesUtil.getCountUrl(count_url, access_token, ids); logger.info("批量获取指定微博的转发数评论数的路径为:"+requestUrl); j = HttpUtil.httpRequestArr(requestUrl, "GET", null); if(j!=null){ logger.info("批量获取指定微博的转发数评论数的结果为:"+j.toString()); }else{ logger.info("批量获取指定微博的转发数评论数的结果为:null"); } }catch(BusinessException e) { logger.info(e.getMessage()); } catch (Exception e) { e.printStackTrace(); } return j; } /**
/** * 将对象转化为Json格式并发送到客户端 <br> * 并提JsonConfig 支持分页查询 * * @author 唐延波 */ public static void sendJSONArrayResponse(final Object object,final String[] excludes, final IPageInfo pageInfo,final HttpServletResponse response) { JSONArray jsonArray = JsonUtil.toJSONArray(object,excludes); if (pageInfo != null) { final JSONObject jsonObject = new JSONObject(); jsonObject.put("total", pageInfo.getTotalCount()); jsonObject.put("rows", jsonArray); sendResponse(jsonObject.toString(), response); } else { sendResponse(jsonArray.toString(), response); } }
@Override public DescribeInstancesResponse.Instance query(String regionId, String instanceId) { DescribeInstancesRequest describe = new DescribeInstancesRequest(); if (regionId == null) regionId = regionIdCnHangzhou; describe.setRegionId(regionId); JSONArray instanceIds = new JSONArray(); instanceIds.add(instanceId); describe.setInstanceIds(instanceIds.toString()); try { DescribeInstancesResponse response = sampleDescribeInstancesResponse(regionId, describe, false); DescribeInstancesResponse.Instance ecs = response.getInstances().get(0); return ecs; } catch (Exception e) { return new DescribeInstancesResponse.Instance(); } }
/** * 查询ecs * * @param regionId * @return */ private EcsServerDO ecsGet(String regionId, ServerDO serverDO) { if (serverDO == null) return null; DescribeInstancesRequest describe = new DescribeInstancesRequest(); if (regionId == null) regionId = regionIdCnHangzhou; describe.setRegionId(regionId); JSONArray ips = new JSONArray(); ips.add(serverDO.getInsideIp()); describe.setInnerIpAddresses(ips.toString()); DescribeInstancesResponse response = sampleDescribeInstancesResponse(regionId, describe, false); return new EcsServerDO(response.getInstances().get(0)); }