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


Java JSON.isEmpty方法代碼示例

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


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

示例1: search

import net.sf.json.JSON; //導入方法依賴的package包/類
public static JSONArray search(String query, String mql_query_file, int limit) {
        try {
            properties.load(new FileInputStream(FREEBASE_PROPERTIES_LOC));
            HttpTransport httpTransport = new NetHttpTransport();
            HttpRequestFactory requestFactory = httpTransport.createRequestFactory();

            GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/search");
            url.put("query", query);
//            url.put("filter", "(all type:/music/artist created:\"The Lady Killer\")");
            url.put("limit", limit);
            String mql_query = IOUtils.toString(new FileInputStream(mql_query_file));

            url.put("mql_output", mql_query);
            url.put("key", properties.get("API_KEY"));
            HttpRequest request = requestFactory.buildGetRequest(url);
            HttpResponse httpResponse = null;
            try {
                httpResponse = request.execute();
            } catch (Exception e) {

            }
            if (httpResponse == null) {
                return null;
            }
            JSON obj = JSONSerializer.toJSON(httpResponse.parseAsString());
            if (obj.isEmpty()) {
                return null;
            }
            JSONObject jsonObject = (JSONObject) obj;
            JSONArray results = jsonObject.getJSONArray("result");
            LogUtils.info(FreebaseUtil.class, results.toString());
            return results;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
 
開發者ID:xcurator,項目名稱:xcurator,代碼行數:38,代碼來源:FreebaseUtil.java

示例2: fetch

import net.sf.json.JSON; //導入方法依賴的package包/類
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;
}
 
開發者ID:xcurator,項目名稱:xcurator,代碼行數:28,代碼來源:FreebaseUtil.java


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