本文整理汇总了Java中twitter4j.internal.org.json.JSONArray.length方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.length方法的具体用法?Java JSONArray.length怎么用?Java JSONArray.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twitter4j.internal.org.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: coordinatesAsGeoLocationArray
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的package包/类
static GeoLocation[][] coordinatesAsGeoLocationArray(JSONArray coordinates) throws TwitterException {
try {
GeoLocation[][] boundingBox = new GeoLocation[coordinates.length()][];
for (int i = 0; i < coordinates.length(); i++) {
JSONArray array = coordinates.getJSONArray(i);
boundingBox[i] = new GeoLocation[array.length()];
for (int j = 0; j < array.length(); j++) {
JSONArray coordinate = array.getJSONArray(j);
boundingBox[i][j] = new GeoLocation(coordinate.getDouble(1), coordinate.getDouble(0));
}
}
return boundingBox;
} catch (JSONException jsone) {
throw new TwitterException(jsone);
}
}
示例2: getURLEntitiesFromJSON
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的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;
}
示例3: createUserList
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的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;
}
}
示例4: createDirectMessageList
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的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;
}
}
示例5: AccountSettingsJSONImpl
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的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);
}
}
示例6: createStatusList
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的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);
}
}
示例7: parseStatuses
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的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;
}
示例8: createUserListList
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的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;
}
}
示例9: VideoInfoImpl
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的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);
}
}
示例10: createLocationList
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的package包/类
static ResponseList<Location> createLocationList(JSONArray list, boolean storeJSON) throws TwitterException {
try {
int size = list.length();
ResponseList<Location> locations =
new ResponseListImpl<Location>(size, null);
for (int i = 0; i < size; i++) {
JSONObject json = list.getJSONObject(i);
Location location = new LocationJSONImpl(json);
locations.add(location);
if (storeJSON) {
DataObjectFactoryUtil.registerJSONObject(location, json);
}
}
if (storeJSON) {
DataObjectFactoryUtil.registerJSONObject(locations, list);
}
return locations;
} catch (JSONException jsone) {
throw new TwitterException(jsone);
} catch (TwitterException te) {
throw te;
}
}
示例11: ControlStreamInfo
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的package包/类
ControlStreamInfo(StreamController controller, JSONObject json) throws TwitterException {
this.controller = controller;
try {
JSONObject info = json.getJSONObject("info");
includeFollowingsActivity = getBoolean("include_followings_activity", info);
includeUserChanges = getBoolean("include_user_changes", info);
replies = getRawString("replies", info);
with = getRawString("with", info);
JSONArray usersJSON = info.getJSONArray("users");
users = new StreamController.User[usersJSON.length()];
for (int i = 0; i < usersJSON.length(); i++) {
users[i] = this.controller.createUser(usersJSON.getJSONObject(i));
}
} catch (JSONException e) {
throw new TwitterException(e);
}
}
示例12: init
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的package包/类
private void init(JSONObject json) throws TwitterException {
try {
JSONObject follow = json.getJSONObject("follow");
JSONArray idList = follow.getJSONArray("friends");
ids = new long[idList.length()];
for (int i = 0; i < idList.length(); i++) {
try {
ids[i] = Long.parseLong(idList.getString(i));
} catch (NumberFormatException nfe) {
throw new TwitterException("Twitter API returned malformed response: " + json, nfe);
}
}
user = new User(follow.getJSONObject("user"));
previousCursor = z_T4JInternalParseUtil.getLong("previous_cursor", json);
nextCursor = z_T4JInternalParseUtil.getLong("next_cursor", json);
} catch (JSONException jsone) {
throw new TwitterException(jsone);
}
}
示例13: createCategoriesList
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的package包/类
static ResponseList<Category> createCategoriesList(JSONArray array, HttpResponse res, Configuration conf) throws TwitterException {
try {
if (conf.isJSONStoreEnabled()) {
DataObjectFactoryUtil.clearThreadLocalMap();
}
ResponseList<Category> categories =
new ResponseListImpl<Category>(array.length(), res);
for (int i = 0; i < array.length(); i++) {
JSONObject json = array.getJSONObject(i);
Category category = new CategoryJSONImpl(json);
categories.add(category);
if (conf.isJSONStoreEnabled()) {
DataObjectFactoryUtil.registerJSONObject(category, json);
}
}
if (conf.isJSONStoreEnabled()) {
DataObjectFactoryUtil.registerJSONObject(categories, array);
}
return categories;
} catch (JSONException jsone) {
throw new TwitterException(jsone);
}
}
示例14: createSavedSearchList
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的package包/类
static ResponseList<SavedSearch> createSavedSearchList(HttpResponse res, Configuration conf) throws TwitterException {
if (conf.isJSONStoreEnabled()) {
DataObjectFactoryUtil.clearThreadLocalMap();
}
JSONArray json = res.asJSONArray();
ResponseList<SavedSearch> savedSearches;
try {
savedSearches = new ResponseListImpl<SavedSearch>(json.length(), res);
for (int i = 0; i < json.length(); i++) {
JSONObject savedSearchesJSON = json.getJSONObject(i);
SavedSearch savedSearch = new SavedSearchJSONImpl(savedSearchesJSON);
savedSearches.add(savedSearch);
if (conf.isJSONStoreEnabled()) {
DataObjectFactoryUtil.registerJSONObject(savedSearch, savedSearchesJSON);
}
}
if (conf.isJSONStoreEnabled()) {
DataObjectFactoryUtil.registerJSONObject(savedSearches, json);
}
return savedSearches;
} catch (JSONException jsone) {
throw new TwitterException(jsone.getMessage() + ":" + res.asString(), jsone);
}
}
示例15: FriendshipJSONImpl
import twitter4j.internal.org.json.JSONArray; //导入方法依赖的package包/类
FriendshipJSONImpl(JSONObject json) throws TwitterException {
super();
try {
id = getLong("id", json);
name = json.getString("name");
screenName = json.getString("screen_name");
JSONArray connections = json.getJSONArray("connections");
for (int i = 0; i < connections.length(); i++) {
String connection = connections.getString(i);
if ("following".equals(connection)) {
following = true;
} else if ("followed_by".equals(connection)) {
followedBy = true;
}
}
} catch (JSONException jsone) {
throw new TwitterException(jsone.getMessage() + ":" + json.toString(), jsone);
}
}