public static User FromJson(VkResponse response)
{
var user = new User
{
Id = response["user_id"] ?? response["uid"] ?? response["id"] ?? 0,
FirstName = response["first_name"],
LastName = response["last_name"],
Sex = response["sex"],
BirthDate = response["bdate"],
City = response["city"],
Country = response["country"],
PhotoPreviews = response,
Online = response["online"],
FriendLists = response["lists"],
Domain = response["domain"],
HasMobile = response["has_mobile"],
MobilePhone = response["mobile_phone"] ?? response["phone"],
HomePhone = response["home_phone"],
Connections = response,
Site = response["site"],
Education = response,
Universities = response["universities"],
Schools = response["schools"],
CanPost = response["can_post"],
CanSeeAllPosts = response["can_see_all_posts"],
CanSeeAudio = response["can_see_audio"],
CanWritePrivateMessage = response["can_write_private_message"],
Status = response["status"],
LastSeen = response["last_seen"],
CommonCount = response["common_count"],
Relation = response["relation"],
Relatives = response["relatives"],
Counters = response["counters"],
ScreenName = response["screen_name"],
Nickname = response["nickname"],
Timezone = response["timezone"],
Language = response["language"],
OnlineMobile = response["online_mobile"],
OnlineApp = response["online_app"],
RelationPartner = response["relation_partner"],
StandInLife = response["personal"],
Interests = response["interests"],
Music = response["music"],
Activities = response["activities"],
Movies = response["movies"],
Tv = response["tv"],
Books = response["books"],
Games = response["games"],
About = response["about"],
Quotes = response["quotes"],
InvitedBy = response["invited_by"],
BanInfo = response["ban_info"],
Deactivated = response["deactivated"],
MaidenName = response["maiden_name"],
BirthdayVisibility = response["bdate_visibility"],
HomeTown = response["home_town"],
ChangeNameRequest = response["name_request"],
BdateVisibility = response["bdate_visibility"],
Contacts = response["contacts"],
Hidden = response["hidden"],
PhotoId = response["photo_id"],
Verified = response["verified"],
HasPhoto = response["has_photo"],
Photo50 = response["photo_50"],
Photo100 = response["photo_100"],
Photo200Orig = response["photo_200_orig"],
Photo200 = response["photo_200"],
Photo400Orig = response["photo_400_orig"],
PhotoMax = response["photo_max"],
PhotoMaxOrig = response["photo_max_orig"],
FollowersCount = response["followers_count"],
Occupation = response["occupation"],
Exports = response["exports"],
WallComments = response["wall_comments"],
CanSendFriendRequest = response["can_send_friend_request"],
IsFavorite = response["is_favorite"],
IsHiddenFromFeed = response["is_hidden_from_feed"],
CropPhoto = response["crop_photo"],
IsFriend = response["is_friend"] == "1",
FriendStatus = response["friend_status"],
Career = response["career"],
Military = response["military"],
Blacklisted = response["blacklisted"],
BlacklistedByMe = response["blacklisted_by_me"]
};
user.IsDeactivated = user.Deactivated != null;
if (response["name"] != null)
{
// Разделить имя и фамилию
var parts = ((string)response["name"]).Split(' ');
if (parts.Length < 2)
{
throw new VkApiException("Invalid name in response");
}
user.FirstName = parts[0];
user.LastName = parts[1];
}
if (user.BirthDate != null && response["bdate_visibility"] == null)
{
var parts = user.BirthDate.Split('.');
user.BirthdayVisibility = parts.Length > 2 ? Enums.BirthdayVisibility.Full : Enums.BirthdayVisibility.OnlyDayAndMonth;
}
return user;
}