当前位置: 首页>>代码示例>>Java>>正文


Java JSONObject.keys方法代码示例

本文整理汇总了Java中twitter4j.internal.org.json.JSONObject.keys方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.keys方法的具体用法?Java JSONObject.keys怎么用?Java JSONObject.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twitter4j.internal.org.json.JSONObject的用法示例。


在下文中一共展示了JSONObject.keys方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createRateLimitStatuses

import twitter4j.internal.org.json.JSONObject; //导入方法依赖的package包/类
static Map<String, RateLimitStatus> createRateLimitStatuses(JSONObject json) throws TwitterException {
    Map<String, RateLimitStatus> map = new HashMap<String, RateLimitStatus>();
    try {
        JSONObject resources = json.getJSONObject("resources");
        Iterator resourceKeys = resources.keys();
        while (resourceKeys.hasNext()) {
            JSONObject resource = resources.getJSONObject((String) resourceKeys.next());
            Iterator endpointKeys = resource.keys();
            while (endpointKeys.hasNext()) {
                String endpoint = (String) endpointKeys.next();
                JSONObject rateLimitStatusJSON = resource.getJSONObject(endpoint);
                RateLimitStatus rateLimitStatus = new RateLimitStatusJSONImpl(rateLimitStatusJSON);
                map.put(endpoint, rateLimitStatus);
            }
        }
        return Collections.unmodifiableMap(map);
    } catch (JSONException jsone) {
        throw new TwitterException(jsone);
    }
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:21,代码来源:RateLimitStatusJSONImpl.java

示例2: createRateLimitStatuses

import twitter4j.internal.org.json.JSONObject; //导入方法依赖的package包/类
static Map<String,RateLimitStatus> createRateLimitStatuses(JSONObject json) throws TwitterException {
    Map<String, RateLimitStatus> map = new HashMap<String, RateLimitStatus>();
    try {
        JSONObject resources = json.getJSONObject("resources");
        Iterator resourceKeys = resources.keys();
        while (resourceKeys.hasNext()) {
            JSONObject resource = resources.getJSONObject((String) resourceKeys.next());
            Iterator endpointKeys = resource.keys();
            while (endpointKeys.hasNext()) {
                String endpoint = (String) endpointKeys.next();
                JSONObject rateLimitStatusJSON = resource.getJSONObject(endpoint);
                RateLimitStatus rateLimitStatus = new RateLimitStatusJSONImpl(rateLimitStatusJSON);
                map.put(endpoint, rateLimitStatus);
            }
        }
        return Collections.unmodifiableMap(map);
    } catch (JSONException jsone) {
        throw new TwitterException(jsone);
    }
}
 
开发者ID:SamKnows,项目名称:skandroid-core,代码行数:21,代码来源:RateLimitStatusJSONImpl.java

示例3: createTrendsList

import twitter4j.internal.org.json.JSONObject; //导入方法依赖的package包/类
static ResponseList<Trends> createTrendsList(HttpResponse res, boolean storeJSON) throws TwitterException {
    JSONObject json = res.asJSONObject();
    ResponseList<Trends> trends;
    try {
        Date asOf = z_T4JInternalParseUtil.parseTrendsDate(json.getString("as_of"));
        JSONObject trendsJson = json.getJSONObject("trends");
        Location location = extractLocation(json, storeJSON);
        trends = new ResponseListImpl<Trends>(trendsJson.length(), res);
        Iterator ite = trendsJson.keys();
        while (ite.hasNext()) {
            String key = (String) ite.next();
            JSONArray array = trendsJson.getJSONArray(key);
            Trend[] trendsArray = jsonArrayToTrendArray(array, storeJSON);
            if (key.length() == 19) {
                // current trends
                trends.add(new TrendsJSONImpl(asOf, location, getDate(key, "yyyy-MM-dd HH:mm:ss"), trendsArray));
            } else if (key.length() == 16) {
                // daily trends
                trends.add(new TrendsJSONImpl(asOf, location, getDate(key, "yyyy-MM-dd HH:mm"), trendsArray));
            } else if (key.length() == 10) {
                // weekly trends
                trends.add(new TrendsJSONImpl(asOf, location, getDate(key, "yyyy-MM-dd"), trendsArray));
            }
        }
        Collections.sort(trends);
        return trends;
    } catch (JSONException jsone) {
        throw new TwitterException(jsone.getMessage() + ":" + res.asString(), jsone);
    }
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:31,代码来源:TrendsJSONImpl.java

示例4: createTrendsList

import twitter4j.internal.org.json.JSONObject; //导入方法依赖的package包/类
static ResponseList<Trends> createTrendsList(HttpResponse res, boolean storeJSON) throws
        TwitterException {
    JSONObject json = res.asJSONObject();
    ResponseList<Trends> trends;
    try {
        Date asOf = z_T4JInternalParseUtil.parseTrendsDate(json.getString("as_of"));
        JSONObject trendsJson = json.getJSONObject("trends");
        Location location = extractLocation(json, storeJSON);
        trends = new ResponseListImpl<Trends>(trendsJson.length(), res);
        Iterator ite = trendsJson.keys();
        while (ite.hasNext()) {
            String key = (String) ite.next();
            JSONArray array = trendsJson.getJSONArray(key);
            Trend[] trendsArray = jsonArrayToTrendArray(array, storeJSON);
            if (key.length() == 19) {
                // current trends
                trends.add(new TrendsJSONImpl(asOf, location, getDate(key
                        , "yyyy-MM-dd HH:mm:ss"), trendsArray));
            } else if (key.length() == 16) {
                // daily trends
                trends.add(new TrendsJSONImpl(asOf, location, getDate(key
                        , "yyyy-MM-dd HH:mm"), trendsArray));
            } else if (key.length() == 10) {
                // weekly trends
                trends.add(new TrendsJSONImpl(asOf, location, getDate(key
                        , "yyyy-MM-dd"), trendsArray));
            }
        }
        Collections.sort(trends);
        return trends;
    } catch (JSONException jsone) {
        throw new TwitterException(jsone.getMessage() + ":" + res.asString(), jsone);
    }
}
 
开发者ID:SamKnows,项目名称:skandroid-core,代码行数:35,代码来源:TrendsJSONImpl.java

示例5: validateJSONObjectSchema

import twitter4j.internal.org.json.JSONObject; //导入方法依赖的package包/类
private static JSONObject validateJSONObjectSchema(JSONObject json, String[] knownNames) throws JSONException {
    boolean debug = false;
    Map<String, String[]> schemaMap = new HashMap<String, String[]>();
    List<String> names = new ArrayList<String>();
    if (debug) {
        System.out.println("validating:" + json);
    }
    for (int i = 0; i < knownNames.length; i++) {
        if (debug) {
            System.out.println("knownName[" + i + "]:" + knownNames[i]);
        }
        String knownName = knownNames[i];
        int index;
        if (-1 != (index = knownName.indexOf("/"))) {
            String parent = knownName.substring(0, index);
            String child = knownName.substring(index + 1);
            String[] array = schemaMap.get(parent);
            if (null == array) {
                schemaMap.put(parent, new String[]{child});
            } else {
                String[] newArray = new String[array.length + 1];
                System.arraycopy(array, 0, newArray, 0, array.length);
                newArray[newArray.length - 1] = child;
                schemaMap.put(parent, newArray);
            }
            names.add(parent);
        } else {
            names.add(knownName);
        }
    }

    Iterator ite = json.keys();
    while (ite.hasNext()) {
        String name = (String) ite.next();
        boolean found = false;
        if (debug) {
            System.out.println("name:" + name);
        }
        for (String elementName : names) {
            if (debug) {
                System.out.println("elementname:" + elementName);
            }
            Object obj = json.get(name);
            if (obj instanceof JSONObject || obj instanceof JSONArray) {
                String[] children = schemaMap.get(name);
                if (null == children) {
                    Assert.fail(elementName + ":" + name + " is not supposed to have any child but has:" + obj);
                } else if (!children[0].equals("*")) {
                    validateJSONSchema(obj, children);
                }
            }
            if (elementName.equals(name)) {
                found = true;
                break;
            }
        }
        if (!found) {
            Assert.fail("unknown element:[" + name + "] in " + json);
        }
    }
    return json;
}
 
开发者ID:SamKnows,项目名称:skandroid-core,代码行数:63,代码来源:DAOTest.java


注:本文中的twitter4j.internal.org.json.JSONObject.keys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。