public MediaEntityJSON(JSONObject json) throws Exception {
   _id = json.optLong("id");
   _mediaUrl = json.getString("media_url");
   _mediaUrlHttps = json.getString("media_url_https");
   _url = json.getString("url");
   _displayUrl = json.getString("display_url");
   _expandedUrl = json.getString("expanded_url");
   JSONArray indicides = json.getJSONArray("indices");
   _startIndex = indicides.getInt(0);
   _endIndex = indicides.getInt(1);
 }
 public UserListJSON(JSONObject json) throws Exception {
   _slug = json.optString("slug");
   _name = Utils.unescape(json.optString("name"));
   _uri = json.optString("uri");
   _subscriberCount = json.optLong("subscriber_count");
   _memberCount = json.optLong("member_count");
   _mode = UserListMode.valueOf(json.optString("mode").toUpperCase());
   _id = json.optLong("id");
   _fullName = Utils.unescape(json.optString("full_name"));
   _description = Utils.unescape(json.optString("description"));
   if (!json.isNull("user")) {
     _user = new UserJSON(json.getJSONObject("user"));
   }
   _following = json.optBoolean("following");
 }
 public TweetJSON(JSONObject json) throws Exception {
   _createdAt = Time.getTwitterSearchDate(json.getString("created_at"));
   if (!json.isNull("entities")) {
     JSONObject entities = json.getJSONObject("entities");
     if (!entities.isNull("urls")) {
       JSONArray urls = entities.optJSONArray("urls");
       ArrayList<UrlEntity> toSet = new ArrayList<UrlEntity>();
       for (int i = 0; i < urls.length(); i++) {
         toSet.add(new UrlEntityJSON(urls.getJSONObject(i)));
       }
       _urlEntities = toSet.toArray(new UrlEntity[0]);
     }
     if (!entities.isNull("hashtags")) {
       JSONArray hashtags = entities.optJSONArray("hashtags");
       ArrayList<HashtagEntity> toSet = new ArrayList<HashtagEntity>();
       for (int i = 0; i < hashtags.length(); i++) {
         toSet.add(new HashtagEntityJSON(hashtags.getJSONObject(i)));
       }
       _hashtagEntities = toSet.toArray(new HashtagEntity[0]);
     }
     if (!entities.isNull("user_mentions")) {
       JSONArray mentions = entities.optJSONArray("user_mentions");
       ArrayList<MentionEntity> toSet = new ArrayList<MentionEntity>();
       for (int i = 0; i < mentions.length(); i++) {
         toSet.add(new MentionEntityJSON(mentions.getJSONObject(i)));
       }
       _mentionEntities = toSet.toArray(new MentionEntity[0]);
     }
     if (!entities.isNull("media")) {
       JSONArray media = entities.optJSONArray("media");
       ArrayList<MediaEntity> toSet = new ArrayList<MediaEntity>();
       for (int i = 0; i < media.length(); i++) {
         toSet.add(new MediaEntityJSON(media.getJSONObject(i)));
       }
       _mediaEntities = toSet.toArray(new MediaEntity[0]);
     }
   }
   _fromUser = json.getString("from_user");
   _fromUserId = json.getLong("from_user_id");
   if (!json.isNull("geo")) {
     _geo = new GeoLocation(json.getJSONObject("geo"));
   }
   if (!json.isNull("place")) {
     _place = new PlaceJSON(json.getJSONObject("place"));
   }
   _id = json.getLong("id");
   _langCode = json.getString("iso_language_code");
   if (!json.isNull("metadata")) {
     JSONObject metadata = json.getJSONObject("metadata");
     if (!metadata.isNull("recent_retweets")) {
       _recentRetweets = metadata.getInt("recent_retweets");
     }
     _resultType = SearchQuery.ResultType.valueOf(metadata.getString("result_type").toUpperCase());
   }
   _profileImageUrl = Utils.unescape(json.getString("profile_image_url"));
   _source = Utils.unescape(json.getString("source"));
   _sourcePlain = Utils.stripAnchor(_source);
   if (!json.isNull("text")) {
     _text = Utils.unescape(json.getString("text"));
   }
   if (!json.isNull("to_user_id")) {
     _toUserId = json.getLong("to_user_id");
   }
 }