Java tutorial
/* * Copyright (C) 2010-2013 The SINA WEIBO Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.danlvse.weebo.model; import android.os.Parcel; import android.os.Parcelable; import org.json.JSONException; import org.json.JSONObject; import java.io.Serializable; /** * Created by zxy on 16/5/25 * * @author SINA * @since 2013-11-24 */ public class User implements Parcelable, Serializable { /** * UIDint64 */ public String id; /** * UID */ public String idstr; /** * */ public String screen_name; /** * ??? */ public String name; /** * ?ID */ public int province; /** * ID */ public int city; /** * */ public String location; /** * ?? */ public String description; /** * ?? */ public String url; /** * ??5050? */ public String profile_image_url; /** * ?URL? */ public String profile_url; /** * () */ public String cover_image_phone; /** * */ public String cover_image; /** * ?? */ public String domain; /** * ? */ public String weihao; /** * m?f?n */ public String gender; /** * ? */ public int followers_count; /** * */ public int friends_count; /** * ? */ public int statuses_count; /** * ? */ public int favourites_count; /** * */ public String created_at; /** * ? */ public boolean following; /** * ????truefalse? */ public boolean allow_all_act_msg; /** * ????truefalse? */ public boolean geo_enabled; /** * ????Vtruefalse? */ public boolean verified; /** * ? */ public int verified_type; /** * ??? */ public String remark; /** * ??? */ public Feed status; /** * ???truefalse? */ public boolean allow_all_comment; /** * ?? */ public String avatar_large; /** * ?? */ public String avatar_hd; /** * ? */ public String verified_reason; /** * ??truefalse? */ public boolean follow_me; /** * ?0??1 */ public int online_status; /** * */ public int bi_followers_count; /** * ?zh-cnzh-tw?en */ public String lang; /** * ???OpenAPI ? */ public String star; public String mbtype; public String mbrank; public String block_word; public static User parse(String jsonString) { try { JSONObject jsonObject = new JSONObject(jsonString); return User.parse(jsonObject); } catch (JSONException e) { e.printStackTrace(); } return null; } public static User parse(JSONObject jsonObject) { if (null == jsonObject) { return null; } User user = new User(); user.id = jsonObject.optString("id", ""); user.idstr = jsonObject.optString("idstr", ""); user.screen_name = jsonObject.optString("screen_name", ""); user.name = jsonObject.optString("name", ""); user.province = jsonObject.optInt("province", -1); user.city = jsonObject.optInt("city", -1); user.location = jsonObject.optString("location", ""); user.description = jsonObject.optString("description", ""); user.url = jsonObject.optString("url", ""); user.profile_image_url = jsonObject.optString("profile_image_url", ""); user.profile_url = jsonObject.optString("profile_url", ""); user.cover_image_phone = jsonObject.optString("cover_image_phone", ""); user.cover_image = jsonObject.optString("cover_image", ""); user.domain = jsonObject.optString("domain", ""); user.weihao = jsonObject.optString("weihao", ""); user.gender = jsonObject.optString("gender", ""); user.followers_count = jsonObject.optInt("followers_count", 0); user.friends_count = jsonObject.optInt("friends_count", 0); user.statuses_count = jsonObject.optInt("statuses_count", 0); user.favourites_count = jsonObject.optInt("favourites_count", 0); user.created_at = jsonObject.optString("created_at", ""); user.following = jsonObject.optBoolean("following", false); user.allow_all_act_msg = jsonObject.optBoolean("allow_all_act_msg", false); user.geo_enabled = jsonObject.optBoolean("geo_enabled", false); user.verified = jsonObject.optBoolean("verified", false); user.verified_type = jsonObject.optInt("verified_type", -1); user.remark = jsonObject.optString("remark", ""); user.status = Feed.parse(jsonObject.optJSONObject("status")); user.allow_all_comment = jsonObject.optBoolean("allow_all_comment", true); user.avatar_large = jsonObject.optString("avatar_large", ""); user.avatar_hd = jsonObject.optString("avatar_hd", ""); user.verified_reason = jsonObject.optString("verified_reason", ""); user.follow_me = jsonObject.optBoolean("follow_me", false); user.online_status = jsonObject.optInt("online_status", 0); user.bi_followers_count = jsonObject.optInt("bi_followers_count", 0); user.lang = jsonObject.optString("lang", ""); user.star = jsonObject.optString("star", ""); user.mbtype = jsonObject.optString("mbtype", ""); user.mbrank = jsonObject.optString("mbrank", ""); user.block_word = jsonObject.optString("block_word", ""); return user; } public User() { } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(this.id); dest.writeString(this.idstr); dest.writeString(this.screen_name); dest.writeString(this.name); dest.writeInt(this.province); dest.writeInt(this.city); dest.writeString(this.location); dest.writeString(this.description); dest.writeString(this.url); dest.writeString(this.profile_image_url); dest.writeString(this.profile_url); dest.writeString(this.cover_image_phone); dest.writeString(this.cover_image); dest.writeString(this.domain); dest.writeString(this.weihao); dest.writeString(this.gender); dest.writeInt(this.followers_count); dest.writeInt(this.friends_count); dest.writeInt(this.statuses_count); dest.writeInt(this.favourites_count); dest.writeString(this.created_at); dest.writeByte(following ? (byte) 1 : (byte) 0); dest.writeByte(allow_all_act_msg ? (byte) 1 : (byte) 0); dest.writeByte(geo_enabled ? (byte) 1 : (byte) 0); dest.writeByte(verified ? (byte) 1 : (byte) 0); dest.writeInt(this.verified_type); dest.writeString(this.remark); dest.writeParcelable(this.status, flags); dest.writeByte(allow_all_comment ? (byte) 1 : (byte) 0); dest.writeString(this.avatar_large); dest.writeString(this.avatar_hd); dest.writeString(this.verified_reason); dest.writeByte(follow_me ? (byte) 1 : (byte) 0); dest.writeInt(this.online_status); dest.writeInt(this.bi_followers_count); dest.writeString(this.lang); dest.writeString(this.star); dest.writeString(this.mbtype); dest.writeString(this.mbrank); dest.writeString(this.block_word); } protected User(Parcel in) { this.id = in.readString(); this.idstr = in.readString(); this.screen_name = in.readString(); this.name = in.readString(); this.province = in.readInt(); this.city = in.readInt(); this.location = in.readString(); this.description = in.readString(); this.url = in.readString(); this.profile_image_url = in.readString(); this.profile_url = in.readString(); this.cover_image_phone = in.readString(); this.cover_image = in.readString(); this.domain = in.readString(); this.weihao = in.readString(); this.gender = in.readString(); this.followers_count = in.readInt(); this.friends_count = in.readInt(); this.statuses_count = in.readInt(); this.favourites_count = in.readInt(); this.created_at = in.readString(); this.following = in.readByte() != 0; this.allow_all_act_msg = in.readByte() != 0; this.geo_enabled = in.readByte() != 0; this.verified = in.readByte() != 0; this.verified_type = in.readInt(); this.remark = in.readString(); this.status = in.readParcelable(Feed.class.getClassLoader()); this.allow_all_comment = in.readByte() != 0; this.avatar_large = in.readString(); this.avatar_hd = in.readString(); this.verified_reason = in.readString(); this.follow_me = in.readByte() != 0; this.online_status = in.readInt(); this.bi_followers_count = in.readInt(); this.lang = in.readString(); this.star = in.readString(); this.mbtype = in.readString(); this.mbrank = in.readString(); this.block_word = in.readString(); } public static final Creator<User> CREATOR = new Creator<User>() { @Override public User createFromParcel(Parcel source) { return new User(source); } @Override public User[] newArray(int size) { return new User[size]; } }; }