Java Code Examples for net.sf.json.JSONObject#getJSONArray()

The following examples show how to use net.sf.json.JSONObject#getJSONArray() . 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 File: GeoServerListCoverageStoresCommand.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public String computeResults(final OperationParams params) throws Exception {
  if ((workspace == null) || workspace.isEmpty()) {
    workspace = geoserverClient.getConfig().getWorkspace();
  }

  final Response listCvgStoresResponse = geoserverClient.getCoverageStores(workspace);

  if (listCvgStoresResponse.getStatus() == Status.OK.getStatusCode()) {
    final JSONObject jsonResponse = JSONObject.fromObject(listCvgStoresResponse.getEntity());
    final JSONArray cvgStores = jsonResponse.getJSONArray("coverageStores");
    return "\nGeoServer coverage stores list for '" + workspace + "': " + cvgStores.toString(2);
  }
  final String errorMessage =
      "Error getting GeoServer coverage stores list for '"
          + workspace
          + "': "
          + listCvgStoresResponse.readEntity(String.class)
          + "\nGeoServer Response Code = "
          + listCvgStoresResponse.getStatus();
  return handleError(listCvgStoresResponse, errorMessage);
}
 
Example 2
Source File: VoteDeleted.java    From gerrit-events with MIT License 6 votes vote down vote up
@Override
public void fromJson(JSONObject json) {
    super.fromJson(json);
    comment = getString(json, COMMENT);
    if (json.containsKey(REVIEWER)) {
        this.reviewer = new Account(json.getJSONObject(REVIEWER));
    }
    if (json.containsKey(REMOVER)) {
        this.remover = new Account(json.getJSONObject(REMOVER));
    }
    if (json.containsKey(APPROVALS)) {
        JSONArray eventApprovals = json.getJSONArray(APPROVALS);
        for (int i = 0; i < eventApprovals.size(); i++) {
            approvals.add(new Approval(eventApprovals.getJSONObject(i)));
        }
    }
}
 
Example 3
Source File: UsergroupClient.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ユーザグループ情報を作成します。<br/>
 * nameパラメータを必ず指定する必要があります。<br/>
 * 既に存在するユーザグループのnameを指定した場合、例外をスローします。
 *
 * @param param {@link UsergroupCreateParam}
 * @return 作成されたユーザグループ情報のusrgrpidのリスト
 */
@SuppressWarnings("unchecked")
public List<String> create(UsergroupCreateParam param) {
    if (param.getName() == null || param.getName().length() == 0) {
        throw new IllegalArgumentException("name is required.");
    }

    JSONObject params = JSONObject.fromObject(param, defaultConfig);
    if (accessor.checkVersion("2.0") >= 0) {
        // api_accessは2.0以降で廃止されたパラメータ
        if (params.containsKey("api_access")) {
            params.remove("api_access");
        }
    }

    JSONObject result = (JSONObject) accessor.execute("usergroup.create", params);

    JSONArray usrgrpids = result.getJSONArray("usrgrpids");
    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(String.class);
    return (List<String>) JSONArray.toCollection(usrgrpids, config);
}
 
Example 4
Source File: JwTagAPI.java    From jeewx-api with Apache License 2.0 6 votes vote down vote up
/**
 * 获取用户身上的标签列表
 */
public static List<Integer> getidlist(String accessToken,String openid){
	List<Integer> list = null;
	if(accessToken != null){
		String requestUrl = getidlist.replace("ACCESS_TOKEN", accessToken);
		Map<String,Object> data = new HashMap<String,Object>();
		data.put("openid", openid);
		JSONObject obj = JSONObject.fromObject(data);
		logger.info("获取用户身上的标签列表 方法执行前json参数---obj: "+obj.toString());
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString());
		Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE);
		if(error == null){
			JSONArray jsonArray = result.getJSONArray("tagid_list");
			list = JSONArray.toList(jsonArray, Integer.class);
		}
		logger.info("获取用户身上的标签列表 方法执行后json参数 : "+result.toString());
	}
	return list;
}
 
Example 5
Source File: UserClient.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ユーザ情報を作成します。<br/>
 * aliasパラメータを必ず指定する必要があります。<br/>
 * 既に存在するユーザのaliasを指定した場合、例外をスローします。
 *
 * @param param {@link UserCreateParam}
 * @return 作成されたユーザ情報のuseridのリスト
 */
@SuppressWarnings("unchecked")
public List<String> create(UserCreateParam param) {
    if (param.getAlias() == null || param.getAlias().length() == 0) {
        throw new IllegalArgumentException("alias is required.");
    }
    if (accessor.checkVersion("2.0") >= 0) {
        if (param.getPasswd() == null || param.getPasswd().length() == 0) {
            throw new IllegalArgumentException("passwd is required.");
        }

        if (param.getUsrgrps() == null || param.getUsrgrps().isEmpty()) {
            throw new IllegalArgumentException("usrgrps is required.");
        }
    }

    JSONObject params = JSONObject.fromObject(param, defaultConfig);
    JSONObject result = (JSONObject) accessor.execute("user.create", params);

    JSONArray userids = result.getJSONArray("userids");
    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(String.class);
    return (List<String>) JSONArray.toCollection(userids, config);
}
 
Example 6
Source File: JwDataCubeAPI.java    From jeewx-api with Apache License 2.0 6 votes vote down vote up
/**
 * 获取消息发送月数据
 * @param bDate 起始时间
 * @param eDate 结束时间
 * @return
 * @throws WexinReqException
 */
public static List<WxDataCubeStreamMsgMonthInfo> getWxDataCubeStreamMsgMonthInfo(String accesstoken,String bDate,String eDate) throws WexinReqException {
	if (accesstoken != null) {
		
		// 封装请求参数
		WxDataCubeStreamMsgMonthParam msgParam = new WxDataCubeStreamMsgMonthParam();
		msgParam.setAccess_token(accesstoken);
		msgParam.setBegin_date(bDate);
		msgParam.setEnd_date(eDate);
		
		// 调用接口
		String requestUrl = GETUPSTREAMMSGMONTH_URL.replace("ACCESS_TOKEN", accesstoken);
		JSONObject obj = JSONObject.fromObject(msgParam);
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString());
		Object error = result.get("errcode");

		// 无错误消息时 返回数据对象
		JSONArray arrayResult = result.getJSONArray("list");
		// 正常返回
		List<WxDataCubeStreamMsgMonthInfo> msgInfoList = null;
		msgInfoList=JSONHelper.toList(arrayResult, WxDataCubeStreamMsgMonthInfo.class);
		return msgInfoList;
	}
	return null;
}
 
Example 7
Source File: JwDataCubeAPI.java    From jeewx-api with Apache License 2.0 6 votes vote down vote up
/**
 * 获取消息发送分布周数据
 * @param bDate 起始时间
 * @param eDate 结束时间
 * @return
 * @throws WexinReqException
 */
public static List<WxDataCubeStreamMsgDistWeekInfo> getWxDataCubeStreamMsgDistWeekInfo(String accesstoken,String bDate,String eDate) throws WexinReqException {
	if (accesstoken != null) {
		
		// 封装请求参数
		WxDataCubeStreamMsgDistWeekParam msgParam = new WxDataCubeStreamMsgDistWeekParam();
		msgParam.setAccess_token(accesstoken);
		msgParam.setBegin_date(bDate);
		msgParam.setEnd_date(eDate);
		
		
		// 调用接口
		String requestUrl = GETUPSTREAMMSGDISTWEEK_URL.replace("ACCESS_TOKEN", accesstoken);
		JSONObject obj = JSONObject.fromObject(msgParam);
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString());
		Object error = result.get("errcode");

		// 无错误消息时 返回数据对象
		JSONArray arrayResult = result.getJSONArray("list");
		// 正常返回
		List<WxDataCubeStreamMsgDistWeekInfo> msgInfoList = null;
		msgInfoList=JSONHelper.toList(arrayResult, WxDataCubeStreamMsgDistWeekInfo.class);
		return msgInfoList;
	}
	return null;
}
 
Example 8
Source File: FreebaseUtil.java    From xcurator with Apache License 2.0 5 votes vote down vote up
public static JSONArray fetch(String query_template_file, Map<String, String> params) {
    try {
        properties.load(new FileInputStream(FREEBASE_PROPERTIES_LOC));
        HttpTransport httpTransport = new NetHttpTransport();
        HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
        String query = IOUtils.toString(new FileInputStream(query_template_file));
        query = manipulateQuery(query, params);
        GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/mqlread");
        url.put("query", query);
        url.put("key", properties.get("API_KEY"));
        System.out.println("URL:" + url);

        HttpRequest request = requestFactory.buildGetRequest(url);
        HttpResponse httpResponse = request.execute();
        JSON obj = JSONSerializer.toJSON(httpResponse.parseAsString());
        if (obj.isEmpty()) {
            return null;
        }
        JSONObject jsonObject = (JSONObject) obj;
        JSONArray results = jsonObject.getJSONArray("result");
        System.out.println(results.toString());
        return results;
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return null;
}
 
Example 9
Source File: JwMultiCustomerAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 判断指定客服是否在线可用
 * @param accessToken
 * @param kfAccount
 * @return
 */
public boolean isOnlineCustServiceAvailable(String accessToken,String kfAccount) {
    List<CustService> custServices = null;
    if (accessToken != null) {
        String requestUrl = GET_ONLINE_CUSTSEVICE_URL.replace("ACCESS_TOKEN", accessToken);
        JSONObject result = WxstoreUtils.httpRequest(requestUrl, "GET", null);
        if(result != null){
            JSONArray info = result.getJSONArray("kf_online_list");
            custServices = JSONHelper.toList(info, CustService.class);
        }
    }
   
    if(custServices!=null&&!custServices.isEmpty()){
        for(Iterator<CustService> it = custServices.iterator();it.hasNext();){
            CustService custService = (CustService)it.next();
            //不在线、没有开启自动接入或者自动接入已满,都返回不可用
            if (custService != null && custService.getKfAccount().equals(kfAccount)
                    && custService.getAutoAccept() > 0
                    && custService.getAutoAccept()>custService.getAcceptedCase()){
                return true;
            }
        }
    }

    return false;
    
}
 
Example 10
Source File: Change.java    From gerrit-events with MIT License 5 votes vote down vote up
@Override
public void fromJson(JSONObject json) {
    project = getString(json, PROJECT);
    branch = getString(json, BRANCH);
    id = getString(json, ID);
    number = getString(json, NUMBER);
    subject = getString(json, SUBJECT);
    createdOn = getDate(json, CREATED_ON);
    lastUpdated = getDate(json, LAST_UPDATED);
    if (json.containsKey(OWNER)) {
        owner = new Account(json.getJSONObject(OWNER));
    }
    if (json.containsKey(COMMENTS)) {
        comments = new ArrayList<Comment>();
        JSONArray eventApprovals = json.getJSONArray(COMMENTS);
        for (int i = 0; i < eventApprovals.size(); i++) {
            comments.add(new Comment(eventApprovals.getJSONObject(i)));
        }
    }
    if (json.containsKey(COMMIT_MESSAGE)) {
        commitMessage = getString(json, COMMIT_MESSAGE);
    }
    if (json.containsKey(TOPIC)) {
        String topicName = getString(json, TOPIC);
        if (StringUtils.isNotEmpty(topicName)) {
            topicObject = new Topic(topicName);
        }
    }

    url = getString(json, URL);
    status = GerritChangeStatus.fromString(getString(json, STATUS));
    wip = getBoolean(json, WIP, false);
    _private = getBoolean(json, PRIVATE, false);
}
 
Example 11
Source File: JwShelfAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 获取所有货架信息
 * @return
 */
public static List<ShelfRInfo> getAllShelf(String newAccessToken) {
	if (newAccessToken != null) {
		String requestUrl = getall_shelf_url.replace("ACCESS_TOKEN", newAccessToken);
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", null);
		// 正常返回
		List<ShelfRInfo> shelfRInfos = null;
		JSONArray info = result.getJSONArray("shelves");
		shelfRInfos = JSONHelper.toList(info, ShelfRInfo.class);
		return shelfRInfos;
	}
	return null;
}
 
Example 12
Source File: JwOrderManagerAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 根据订单状态/创建时间获取订单详情
 * @param orderPara
 * @return
 */
public static List<OrderInfo> getByFilter(String newAccessToken, OrderPara orderPara) {
	if (newAccessToken != null) {
		String requestUrl = getfilter_order_url.replace("ACCESS_TOKEN", newAccessToken);
		JSONObject obj = JSONObject.fromObject(orderPara);
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "GET", obj.toString());
		// 正常返回
		List<OrderInfo> orderInfos = null;
		JSONArray info = result.getJSONArray("order_list");
		orderInfos = JSONHelper.toList(info, OrderInfo.class);
		return orderInfos;
	}
	return null;
}
 
Example 13
Source File: HostgroupClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ホストグループ情報を削除します。<br/>
 * groupidパラメータを必ず指定する必要があります。<br/>
 * 存在しないgroupidを指定した場合、例外をスローします。<br/>
 *
 * @param groupids 削除するホストグループのIDのリスト
 * @return 削除したホストグループ情報のhostgroupidのリスト
 */
@SuppressWarnings("unchecked")
public List<String> delete(List<String> groupids) {
    if (groupids == null || groupids.isEmpty()) {
        throw new IllegalArgumentException("groupid is required.");
    }

    JSONArray params;
    if (accessor.checkVersion("2.0") < 0) {
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        for (String groupid : groupids) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("groupid", groupid);
            list.add(map);
        }
        params = JSONArray.fromObject(list, defaultConfig);
    } else {
        params = JSONArray.fromObject(groupids, defaultConfig);
    }

    JSONObject result = (JSONObject) accessor.execute("hostgroup.delete", params);

    JSONArray hostgroupids = result.getJSONArray("groupids");
    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(String.class);
    return (List<String>) JSONArray.toCollection(hostgroupids, config);
}
 
Example 14
Source File: JwShopAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 增加门店
 */
public static String getShopCategorys(String newAccessToken) {
	if (newAccessToken != null) {
		String requestUrl = shop_category_url.replace("ACCESS_TOKEN", newAccessToken);
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "GET",null);
		JSONArray info = result.getJSONArray("category_list");
		String str = null;
		str = JSONHelper.toBean(info, String.class);
		return str;
	}
	return null;
}
 
Example 15
Source File: IdentityAction.java    From anychat with MIT License 5 votes vote down vote up
/**
 * 获取好友列表相当于组里的所有人
 * 
 * @param userGroupTopId
 *            组id
 * @param token
 *            身份
 * @return
 */
public static List<UserData> getFriendList(String userGroupTopId, String token) {
	JSONObject js = new JSONObject();
	js.put("hOpCode", "13");
	js.put("userGroupTopId", userGroupTopId);
	Map<String, String> header = new HashMap<>();
	header.put("hOpCode", "13");
	header.put("token", token);
	byte[] returnByte = HttpUtil.send(js.toString(), CommonConfigChat.IDENTITY_URL, header, HttpUtil.POST);
	if (returnByte != null) {
		String str = null;
		try {
			str = new String(returnByte, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			WSManager.log.error("返回字符串解析异常", e);
		}
		JSONObject returnjs = JSONObject.fromObject(str);
		// 如果返回的是错误类型,说明用户中心拦截器没通过
		if (returnjs.getString("hOpCode").equals("0")) {
			return null;
		}
		JSONArray jsArray = returnjs.getJSONArray("user");
		List<UserData> list = new ArrayList<>();
		for (int i = 0; i < jsArray.size(); i++) {
			JSONObject user = jsArray.getJSONObject(i);
			UserData userData = new UserData(user);
			list.add(userData);
		}
		return list;
	}
	return null;
}
 
Example 16
Source File: JwShopAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 查询门店列表
 */
public static List<BaseInfo> getshops(String newAccessToken, BusinessReq businessReq) {
	if (newAccessToken != null) {
		String requestUrl = search_shop_url.replace("ACCESS_TOKEN", newAccessToken);
		JSONObject obj = JSONObject.fromObject(businessReq);
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString());
		// 正常返回
		List<BaseInfo> baseInfos = null;
		JSONArray info = result.getJSONArray("business_list");
		baseInfos = JSONHelper.toList(info, BaseInfo.class);
		return baseInfos;
	}
	return null;
}
 
Example 17
Source File: CommentAdded.java    From gerrit-events with MIT License 5 votes vote down vote up
@Override
public void fromJson(JSONObject json) {
    super.fromJson(json);
    comment = getString(json, COMMENT);
    if (json.containsKey(AUTHOR)) {
        account = new Account(json.getJSONObject(AUTHOR));
    }
    if (json.containsKey(APPROVALS)) {
        JSONArray eventApprovals = json.getJSONArray(APPROVALS);
        for (int i = 0; i < eventApprovals.size(); i++) {
            approvals.add(new Approval(eventApprovals.getJSONObject(i)));
        }
    }
}
 
Example 18
Source File: ItemClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * アイテム情報を削除します。<br/>
 * itemidsパラメータを必ず指定する必要があります。<br/>
 * 存在しないitemidを指定した場合、例外をスローします。
 *
 * @param itemids itemids
 * @return 削除したアイテム情報のitemidのリスト
 */
public List<String> delete(List<String> itemids) {
    if (itemids == null || itemids.isEmpty()) {
        throw new IllegalArgumentException("itemid is required.");
    }

    JSONArray params = JSONArray.fromObject(itemids, defaultConfig);
    JSONObject result = (JSONObject) accessor.execute("item.delete", params);

    JSONArray itemIds = result.getJSONArray("itemids");
    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(String.class);

    List<?> list = (List<?>) JSONArray.toCollection(itemIds, config);

    List<String> itemIdsList = new ArrayList<String>();
    for (Object object : list) {
        if (object instanceof String) {
            itemIdsList.add(String.class.cast(object));
        } else {
            itemIdsList.add(object.toString());
        }
    }

    return itemIdsList;
}
 
Example 19
Source File: JwServiceIpAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 获取服务的ip列表信息
 * @param accessToke
 * @return
 * @throws WexinReqException
 */
public static List<String> getServiceIpList(String accessToke) throws WexinReqException{
	ServiceIP param = new ServiceIP();
	param.setAccess_token(accessToke);
	JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(param);
	Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE);
	List<String> lstServiceIp = null;
	JSONArray infoArray = result.getJSONArray(RETURN_INFO_NAME);
	lstServiceIp = new ArrayList<String>(infoArray.size());
	for (int i = 0; i < infoArray.size(); i++) {
		lstServiceIp.add(infoArray.getString(i));
	}
	return lstServiceIp;
}
 
Example 20
Source File: FreeBaseLinker.java    From xcurator with Apache License 2.0 4 votes vote down vote up
@Override
public Set<String> findTypesForResource(String str, StringMetric metric, double threshold) {
    LogUtils.info(this.getClass(), "str=" + str);
    Set<String> types = new HashSet<String>();
    String query = str.replaceAll("\\s", "+").replaceAll("%", "").replaceAll("\"", "");
    final JSONArray json = FreebaseUtil.search(query, "resources/freebase/type_query.json", 5);
    if (json == null) {
        return null;
    }
    // Iterate through all elements in the array whose key name is "result"
    for (int i = 0; i < json.size(); i++) {

        // Get the element
        JSONObject resultElement = (JSONObject) json.get(i);

        // The boolean value to check if a element with name
        // similar to the provided text value has been found
        boolean same = false;

        // Get the "name" of the element
        String name = "";
        try {
            name = resultElement.getString("name");
        } catch (Exception e) {
        }

        // Check if the name and the provided text value is similar
        if (metric.getSimilarity(str, name) >= threshold) {
            same = true;
        } // If the name of the element is not similar, try to find
        // if a similar alias exists
        else {
            JSONArray aliases = resultElement.getJSONArray("/common/topic/alias");
            for (int j = 0; j < aliases.size(); j++) {
                String alias = aliases.getString(j);
                if (metric.getSimilarity(str, alias) >= threshold) {
                    same = true;
                    break;
                }
            }
        }

        // If the current element has a name or an alias that is similar
        // to the provided text value
        if (same) {

            // Find the array of types of the element
            JSONArray typeArray = resultElement.getJSONArray("type");

            // Iterate through each type
            for (int j = 0; j < typeArray.size(); j++) {
                // For each type, get its typeID, which looks something like "/music/release"
                String typeId = (((JSONObject) typeArray.get(j)).getString("id"));
                // Add the prefix to the typeID, which now looks something like
                // "http://rdf.freebase.com/rdf/music.release"
                typeId = freebaseTypePrefix + typeId.substring(1).replaceAll("/", ".");
                // Skip the current iteration if the typeID ends with "topic"
                if (typeId.endsWith("topic")) {
                    continue;
                }
                // Add the typeID to types
                types.add(typeId);
            }
        }
    }

    return types;
}