コード例 #1
0
 EducationJSONImpl(JSONObject json) throws FacebookException {
   try {
     if (!json.isNull("year")) {
       JSONObject yearJSON = json.getJSONObject("year");
       year = new IdNameEntityJSONImpl(yearJSON);
     }
     type = getRawString("type", json);
     if (!json.isNull("school")) {
       JSONObject schoolJSON = json.getJSONObject("school");
       school = new IdNameEntityJSONImpl(schoolJSON);
     }
     if (!json.isNull("degree")) {
       JSONObject degreeJSON = json.getJSONObject("degree");
       degree = new IdNameEntityJSONImpl(degreeJSON);
     }
     if (!json.isNull("concentration")) {
       JSONArray concentrationJSONArray = json.getJSONArray("concentration");
       concentration = new ArrayList<IdNameEntity>();
       for (int i = 0; i < concentrationJSONArray.length(); i++) {
         concentration.add(new IdNameEntityJSONImpl(concentrationJSONArray.getJSONObject(i)));
       }
     } else {
       concentration = Collections.emptyList();
     }
     if (!json.isNull("classes")) {
       JSONArray classesJSONArray = json.getJSONArray("classes");
       classes = new ArrayList<EducationClass>();
       for (int i = 0; i < classesJSONArray.length(); i++) {
         classes.add(new EducationClassJSONImpl(classesJSONArray.getJSONObject(i)));
       }
     } else {
       classes = Collections.emptyList();
     }
     if (!json.isNull("with")) {
       JSONArray withJSONArray = json.getJSONArray("with");
       with = new ArrayList<IdNameEntity>();
       for (int i = 0; i < withJSONArray.length(); i++) {
         with.add(new IdNameEntityJSONImpl(withJSONArray.getJSONObject(i)));
       }
     } else {
       with = Collections.emptyList();
     }
   } catch (JSONException jsone) {
     throw new FacebookException(jsone);
   }
 }
コード例 #2
0
 EducationClassJSONImpl(JSONObject json) throws FacebookException {
   try {
     if (!json.isNull("with")) {
       JSONArray withJSONArray = json.getJSONArray("with");
       with = new ArrayList<IdNameEntity>();
       for (int i = 0; i < withJSONArray.length(); i++) {
         with.add(new IdNameEntityJSONImpl(withJSONArray.getJSONObject(i)));
       }
     } else {
       with = Collections.emptyList();
     }
     description = getRawString("description", json);
   } catch (JSONException jsone) {
     throw new FacebookException(jsone.getMessage() + ":" + json.toString(), jsone);
   }
 }
コード例 #3
0
 private void init(JSONObject json) throws FacebookException {
   try {
     id = getRawString("id", json);
     name = getRawString("name", json);
     firstName = getRawString("first_name", json);
     middleName = getRawString("middle_name", json);
     lastName = getRawString("last_name", json);
     gender = getRawString("gender", json);
     if (!json.isNull("locale")) {
       String[] _locale = getRawString("locale", json).split("_");
       String language = _locale[0];
       String country = _locale[1];
       locale = new Locale(language, country);
     }
     if (!json.isNull("languages")) {
       JSONArray languagesJSONArray = json.getJSONArray("languages");
       final int size = languagesJSONArray.length();
       languages = new ArrayList<IdNameEntity>(size);
       for (int i = 0; i < size; i++) {
         languages.add(new IdNameEntityJSONImpl(languagesJSONArray.getJSONObject(i)));
       }
     } else {
       languages = Collections.emptyList();
     }
     link = getURL("link", json);
     username = getRawString("username", json);
     thirdPartyId = getRawString("third_party_id", json);
     installed = getBoolean("installed", json);
     // Using the current time to compute the timezone offset is technically wrong, because
     // the timezone value corresponds to the user's last login, but it's the best we can do
     long currentTime = System.currentTimeMillis();
     timezone = getTimeZoneOffset("timezone", json, currentTime);
     updatedTime = getISO8601Datetime("updated_time", json);
     verified = getBoolean("verified", json);
     bio = getRawString("bio", json);
     birthday = getRawString("birthday", json);
     if (!json.isNull("cover")) {
       JSONObject coverJSON = json.getJSONObject("cover");
       cover = new CoverJSONImpl(coverJSON);
     }
     if (!json.isNull("education")) {
       JSONArray educationJSONArray = json.getJSONArray("education");
       final int size = educationJSONArray.length();
       education = new ArrayList<User.Education>(size);
       for (int i = 0; i < size; i++) {
         education.add(new EducationJSONImpl(educationJSONArray.getJSONObject(i)));
       }
     } else {
       education = Collections.emptyList();
     }
     email = getRawString("email", json);
     if (!json.isNull("hometown")) {
       String hometownRawString = getRawString("hometown", json);
       if (hometownRawString.startsWith("{")) {
         JSONObject hometownJSON = json.getJSONObject("hometown");
         hometown = new IdNameEntityJSONImpl(hometownJSON);
       } else {
         hometown = new IdNameEntityJSONImpl(hometownRawString);
       }
     }
     if (!json.isNull("interestedIn")) {
       JSONArray interestedInJSONArray = json.getJSONArray("interested_in");
       final int size = interestedInJSONArray.length();
       interestedIn = new ArrayList<String>(size);
       for (int i = 0; i < size; i++) {
         interestedIn.add(interestedInJSONArray.getString(i));
       }
     } else {
       interestedIn = Collections.emptyList();
     }
     if (!json.isNull("location")) {
       JSONObject locationJSON = json.getJSONObject("location");
       location = new IdNameEntityJSONImpl(locationJSON);
     }
     political = getRawString("political", json);
     if (!json.isNull("favorite_athletes")) {
       JSONArray favoriteAthletesJSONArray = json.getJSONArray("favorite_athletes");
       final int size = favoriteAthletesJSONArray.length();
       favoriteAthletes = new ArrayList<IdNameEntity>(size);
       for (int i = 0; i < favoriteAthletesJSONArray.length(); i++) {
         favoriteAthletes.add(
             new IdNameEntityJSONImpl(favoriteAthletesJSONArray.getJSONObject(i)));
       }
     } else {
       favoriteAthletes = Collections.emptyList();
     }
     if (!json.isNull("favorite_teams")) {
       JSONArray favoriteTeamsJSONArray = json.getJSONArray("favorite_teams");
       final int size = favoriteTeamsJSONArray.length();
       favoriteTeams = new ArrayList<IdNameEntity>(size);
       for (int i = 0; i < size; i++) {
         favoriteTeams.add(new IdNameEntityJSONImpl(favoriteTeamsJSONArray.getJSONObject(i)));
       }
     } else {
       favoriteTeams = Collections.emptyList();
     }
     if (!json.isNull("picture")) {
       String pictureRawString = getRawString("picture", json);
       if (pictureRawString.startsWith("{")) {
         JSONObject pictureJSONObject = json.getJSONObject("picture");
         picture = new PictureJSONImpl(pictureJSONObject);
       } else {
         picture = new PictureJSONImpl(getURL("picture", json));
       }
     }
     quotes = getRawString("quotes", json);
     relationshipStatus = getRawString("relationship_status", json);
     religion = getRawString("religion", json);
     if (!json.isNull("significant_other")) {
       JSONObject significantOtherJSONObject = json.getJSONObject("significant_other");
       significantOther = new IdNameEntityJSONImpl(significantOtherJSONObject);
     }
     if (!json.isNull("video_upload_limits")) {
       JSONObject videoUploadLimitsJSONObject = json.getJSONObject("video_upload_limits");
       videoUploadLimits = new VideoUploadLimitsJSONImpl(videoUploadLimitsJSONObject);
     }
     website = getURL("website", json);
     if (!json.isNull("work")) {
       JSONArray workJSONArray = json.getJSONArray("work");
       final int size = workJSONArray.length();
       work = new ArrayList<Work>(size);
       for (int i = 0; i < size; i++) {
         work.add(new WorkJSONImpl(workJSONArray.getJSONObject(i)));
       }
     } else {
       work = Collections.emptyList();
     }
     if (!json.isNull("age_range")) {
       JSONObject ageRangeJSONObject = json.getJSONObject("age_range");
       ageRange = new AgeRangeJSONImpl(ageRangeJSONObject);
     }
     if (!json.isNull("metadata")) {
       JSONObject metadataJSONObject = json.getJSONObject("metadata");
       metadata = new MetadataImpl(metadataJSONObject);
     }
   } catch (JSONException jsone) {
     throw new FacebookException(jsone.getMessage() + ":" + json.toString(), jsone);
   }
 }