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


Java JSONObject类代码示例

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


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

示例1: init

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
private void init(JSONObject json) throws TwitterException {
    try {
        JSONArray indicesArray = json.getJSONArray("indices");
        setStart(indicesArray.getInt(0));
        setEnd(indicesArray.getInt(1));

        if (!json.isNull("name")) {
            this.name = json.getString("name");
        }
        if (!json.isNull("screen_name")) {
            this.screenName = json.getString("screen_name");
        }
        id = z_T4JInternalParseUtil.getLong("id", json);
    } catch (JSONException jsone) {
        throw new TwitterException(jsone);
    }
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:18,代码来源:UserMentionEntityJSONImpl.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:sprinklr-inc,项目名称:twitter4j-ads,代码行数:21,代码来源:RateLimitStatusJSONImpl.java

示例3: getURLEntitiesFromJSON

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
/**
 * Get URL Entities from JSON Object.
 * returns URLEntity array by entities/[category]/urls/url[]
 *
 * @param json     user json object
 * @param category entities category. e.g. "description" or "url"
 * @return URLEntity array by entities/[category]/urls/url[]
 * @throws JSONException
 * @throws TwitterException
 */
private static URLEntity[] getURLEntitiesFromJSON(JSONObject json, String category) throws JSONException, TwitterException {
    if (!json.isNull("entities")) {
        JSONObject entitiesJSON = json.getJSONObject("entities");
        if (!entitiesJSON.isNull(category)) {
            JSONObject descriptionEntitiesJSON = entitiesJSON.getJSONObject(category);
            if (!descriptionEntitiesJSON.isNull("urls")) {
                JSONArray urlsArray = descriptionEntitiesJSON.getJSONArray("urls");
                int len = urlsArray.length();
                URLEntity[] urlEntities = new URLEntity[len];
                for (int i = 0; i < len; i++) {
                    urlEntities[i] = new URLEntityJSONImpl(urlsArray.getJSONObject(i));
                }
                return urlEntities;
            }
        }
    }
    return null;
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:29,代码来源:UserJSONImpl.java

示例4: createUserList

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
static ResponseList<User> createUserList(JSONArray list, HttpResponse res, Configuration conf) throws TwitterException {
    try {
        if (conf.isJSONStoreEnabled()) {
            DataObjectFactoryUtil.clearThreadLocalMap();
        }
        int size = list.length();
        ResponseList<User> users = new ResponseListImpl<User>(size, res);
        for (int i = 0; i < size; i++) {
            JSONObject json = list.getJSONObject(i);
            User user = new UserJSONImpl(json);
            users.add(user);
            if (conf.isJSONStoreEnabled()) {
                DataObjectFactoryUtil.registerJSONObject(user, json);
            }
        }
        if (conf.isJSONStoreEnabled()) {
            DataObjectFactoryUtil.registerJSONObject(users, list);
        }
        return users;
    } catch (JSONException jsone) {
        throw new TwitterException(jsone);
    } catch (TwitterException te) {
        throw te;
    }
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:26,代码来源:UserJSONImpl.java

示例5: createDirectMessageList

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
static ResponseList<DirectMessage> createDirectMessageList(HttpResponse res, Configuration conf) throws TwitterException {
    try {
        if (conf.isJSONStoreEnabled()) {
            DataObjectFactoryUtil.clearThreadLocalMap();
        }
        JSONArray list = res.asJSONArray();
        int size = list.length();
        ResponseList<DirectMessage> directMessages = new ResponseListImpl<DirectMessage>(size, res);
        for (int i = 0; i < size; i++) {
            JSONObject json = list.getJSONObject(i);
            DirectMessage directMessage = new DirectMessageJSONImpl(json);
            directMessages.add(directMessage);
            if (conf.isJSONStoreEnabled()) {
                DataObjectFactoryUtil.registerJSONObject(directMessage, json);
            }
        }
        if (conf.isJSONStoreEnabled()) {
            DataObjectFactoryUtil.registerJSONObject(directMessages, list);
        }
        return directMessages;
    } catch (JSONException jsone) {
        throw new TwitterException(jsone);
    } catch (TwitterException te) {
        throw te;
    }
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:27,代码来源:DirectMessageJSONImpl.java

示例6: AccountSettingsJSONImpl

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
private AccountSettingsJSONImpl(HttpResponse res, JSONObject json) throws TwitterException {
    super(res);
    try {
        JSONObject sleepTime = json.getJSONObject("sleep_time");
        SLEEP_TIME_ENABLED = getBoolean("enabled", sleepTime);
        SLEEP_START_TIME = sleepTime.getString("start_time");
        SLEEP_END_TIME = sleepTime.getString("end_time");
        if (json.isNull("trend_location")) {
            TREND_LOCATION = new Location[0];
        } else {
            JSONArray locations = json.getJSONArray("trend_location");
            TREND_LOCATION = new Location[locations.length()];
            for (int i = 0; i < locations.length(); i++) {
                TREND_LOCATION[i] = new LocationJSONImpl(locations.getJSONObject(i));
            }
        }
        GEO_ENABLED = getBoolean("geo_enabled", json);
        LANGUAGE = json.getString("language");
        ALWAYS_USE_HTTPS = getBoolean("always_use_https", json);
        DISCOVERABLE_BY_EMAIL = getBoolean("discoverable_by_email", json);
        TIMEZONE = new TimeZoneJSONImpl(json.getJSONObject("time_zone"));
    } catch (JSONException e) {
        throw new TwitterException(e);
    }
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:26,代码来源:AccountSettingsJSONImpl.java

示例7: init

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
private void init(JSONObject json) throws TwitterException {
    try {
        JSONArray indicesArray = json.getJSONArray("indices");
        setStart(indicesArray.getInt(0));
        setEnd(indicesArray.getInt(1));

        this.url = json.getString("url");
        if (!json.isNull("expanded_url")) {
            // sets expandedURL to url if expanded_url is null
            // http://jira.twitter4j.org/browse/TFJ-704
            this.expandedURL = json.getString("expanded_url");
        }else{
            this.expandedURL = url;
        }

        if (!json.isNull("display_url")) {
            // sets displayURL to url if expanded_url is null
            // http://jira.twitter4j.org/browse/TFJ-704
            this.displayURL = json.getString("display_url");
        }else{
            this.displayURL = url;
        }
    } catch (JSONException jsone) {
        throw new TwitterException(jsone);
    }
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:27,代码来源:URLEntityJSONImpl.java

示例8: createStatusList

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
public static ResponseList<Status> createStatusList(HttpResponse res, Configuration conf) throws TwitterException {
    try {
        if (conf.isJSONStoreEnabled()) {
            DataObjectFactoryUtil.clearThreadLocalMap();
        }
        JSONArray list = res.asJSONArray();
        int size = list.length();
        ResponseList<Status> statuses = new ResponseListImpl<Status>(size, res);
        for (int i = 0; i < size; i++) {
            JSONObject json = list.getJSONObject(i);
            Status status = new StatusJSONImpl(json);
            if (conf.isJSONStoreEnabled()) {
                DataObjectFactoryUtil.registerJSONObject(status, json);
            }
            statuses.add(status);
        }
        if (conf.isJSONStoreEnabled()) {
            DataObjectFactoryUtil.registerJSONObject(statuses, list);
        }
        return statuses;
    } catch (JSONException jsone) {
        throw new TwitterException(jsone);
    }
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:25,代码来源:StatusJSONImpl.java

示例9: parseStatuses

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
public static ResponseList<Status> parseStatuses(Configuration conf, JSONArray list) throws JSONException, TwitterException {
    if (conf.isJSONStoreEnabled()) {
        DataObjectFactoryUtil.clearThreadLocalMap();
    }
    int size = list.length();
    ResponseList<Status> statuses = new ResponseListImpl<Status>(size, null);
    for (int i = 0; i < size; i++) {
        JSONObject json = list.getJSONObject(i);
        Status status = new StatusJSONImpl(json);
        if (conf.isJSONStoreEnabled()) {
            DataObjectFactoryUtil.registerJSONObject(status, json);
        }
        statuses.add(status);
    }
    if (conf.isJSONStoreEnabled()) {
        DataObjectFactoryUtil.registerJSONObject(statuses, list);
    }
    return statuses;
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:20,代码来源:StatusJSONImpl.java

示例10: init

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
private void init(JSONObject json) throws TwitterException {
    id = getLong("id", json);
    idStr = getRawString("id_str", json);
    name = getRawString("name", json);
    fullName = getRawString("full_name", json);
    slug = getRawString("slug", json);
    description = getRawString("description", json);
    subscriberCount = getInt("subscriber_count", json);
    memberCount = getInt("member_count", json);
    uri = getRawString("uri", json);
    mode = "public".equals(getRawString("mode", json));
    following = getBoolean("following", json);

    try {
        if (!json.isNull("user")) {
            user = new UserJSONImpl(json.getJSONObject("user"));
        }
    } catch (JSONException jsone) {
        throw new TwitterException(jsone.getMessage() + ":" + json.toString(), jsone);
    }
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:22,代码来源:UserListJSONImpl.java

示例11: createUserListList

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
static ResponseList<UserList> createUserListList(HttpResponse res, Configuration conf) throws TwitterException {
    try {
        if (conf.isJSONStoreEnabled()) {
            DataObjectFactoryUtil.clearThreadLocalMap();
        }
        JSONArray list = res.asJSONArray();
        int size = list.length();
        ResponseList<UserList> users = new ResponseListImpl<UserList>(size, res);
        for (int i = 0; i < size; i++) {
            JSONObject userListJson = list.getJSONObject(i);
            UserList userList = new UserListJSONImpl(userListJson);
            users.add(userList);
            if (conf.isJSONStoreEnabled()) {
                DataObjectFactoryUtil.registerJSONObject(userList, userListJson);
            }
        }
        if (conf.isJSONStoreEnabled()) {
            DataObjectFactoryUtil.registerJSONObject(users, list);
        }
        return users;
    } catch (JSONException jsone) {
        throw new TwitterException(jsone);
    } catch (TwitterException te) {
        throw te;
    }
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:27,代码来源:UserListJSONImpl.java

示例12: VideoInfoImpl

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
VideoInfoImpl(JSONObject jsonObject) throws TwitterException {
    aspectRatio = new ArrayList<>();
    variants = new ArrayList<>();
    try {
        if (jsonObject.has("aspect_ratio")) {
            JSONArray aspectRationArray = jsonObject.getJSONArray("aspect_ratio");
            for (int i = 0; i < aspectRationArray.length(); i++) {
                aspectRatio.add(aspectRationArray.getInt(i));
            }
        }
        if (jsonObject.has("duration_millis")) {
            millis = jsonObject.getLong("duration_millis");
        }

        if (jsonObject.has("variants")) {
            JSONArray variantJSONArray = jsonObject.getJSONArray("variants");
            for (int i = 0; i < variantJSONArray.length(); i++) {
                variants.add(new VariantImpl(variantJSONArray.getJSONObject(i)));
            }
        }
    } catch (JSONException e) {
        throw new TwitterException(e);
    }
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:25,代码来源:MediaEntityJSONImpl.java

示例13: extractLocation

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
private static Location extractLocation(JSONObject json, boolean storeJSON) throws TwitterException {
    if (json.isNull("locations")) {
        return null;
    }
    ResponseList<Location> locations;
    try {
        locations = LocationJSONImpl.createLocationList(json.getJSONArray("locations"), storeJSON);
    } catch (JSONException e) {
        throw new AssertionError("locations can't be null");
    }
    Location location;
    if (0 != locations.size()) {
        location = locations.get(0);
    } else {
        location = null;
    }
    return location;
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:19,代码来源:TrendsJSONImpl.java

示例14: init

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
private void init(JSONObject json) throws TwitterException {
    try {
        mediaId = getLong("media_id", json);
        mediaIdString = getRawString("media_id", json);
        size = getLong("size", json);
        if (!json.isNull("image")) {
            image = new TwitterImageJSONImpl(json);
        }
        if (!json.isNull("expires_after_secs")) {
            expiresAfterSecs = getLong("expires_after_secs", json);
        }
        if (!json.isNull("processing_info")) {
            JSONObject processingInfo = new JSONObject(getRawString("processing_info", json));
            if (!processingInfo.isNull("state")) {
                state = getRawString("state", processingInfo);
            }
        }
    } catch (Exception jsone) {
        throw new TwitterException(jsone);
    }
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:22,代码来源:TwitterUploadMediaResponseImpl.java

示例15: LocationJSONImpl

import twitter4j.internal.org.json.JSONObject; //导入依赖的package包/类
public LocationJSONImpl(JSONObject location) throws TwitterException {
    super(location);
    try {
        woeid = getInt("woeid", location);
        countryName = getUnescapedString("country", location);
        countryCode = getRawString("countryCode", location);
        if (!location.isNull("placeType")) {
            JSONObject placeJSON = location.getJSONObject("placeType");
            placeName = getUnescapedString("name", placeJSON);
            placeCode = getInt("code", placeJSON);
        } else {
            placeName = null;
            placeCode = -1;
        }
        name = getUnescapedString("name", location);
        url = getUnescapedString("url", location);
    } catch (JSONException jsone) {
        throw new TwitterException(jsone);
    }
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:21,代码来源:LocationJSONImpl.java


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