how to parse this in iphone - iphone

{
education = (
{
school = {
id = 108102169223234;
name = psss;
};
type = College;
year = {
id = 142833822398097;
name = 2010;
};
}
);
email = "amvijaycse#gmail.com";
"first_name" = Vijay;
gender = male;
id = 100000782204693;
"last_name" = Kumar;
link = "http://www.facebook.com/profile.php?id=100000782204693";
locale = "en_US";
location = {
id = 106377336067638;
name = "Bangalore, India";
};
name = "Vijay Kumar";
timezone = "5.5";
"updated_time" = "2010-11-21T07:45:11+0000";
}
i needed email,firstname,lastname.

[EDIT: Removed because it was inaccurate]

Related

Swift Codable: How do I make multiple objects from embedded data

Say I have JSON like this:
["conferences": <__NSArrayI 0x60c00002f720>(
{
alias = Conference1;
divisions = (
{
alias = "Division 1";
id = "b95cd27d-d631-4fe1-bc05-0ae47fc0b14b";
name = "Division 1";
teams = (
{
alias = OXC;
id = "768c92aa-75ff-4a43-bcc0-f2798c2e1724";
market = East;
name = Rams;
references = (
{
id = Rams;
origin = gsis;
}
);
{
alias = AXC;
id = "768c92aa-75ff-4a43-bcc0-f2798c2e1724";
market = East;
name = Platypus;
references = (
{
id = Platypus;
origin = gsis;
}
);
},
{
alias = "Division 2";
id = "b95cd27d-d631-4fe1-bc05-0ae47fc0b14b";
name = "Division 2";
teams = (
{
alias = NXC;
id = "768c92aa-75ff-4a43-bcc0-f2798c2e1724";
market = West;
name = Ants;
references = (
{
id = Ants;
origin = gsis;
}
);
{
alias = QXC;
id = "768c92aa-75ff-4a43-bcc0-f2798c2e1724";
market = West;
name = Bulls;
references = (
{
id = Bulls;
origin = gsis;
}
);
},
}]
I'm at a lost as to how to create an object that contains the team data but also the Conference and Division alias.
I started down this path but this seems like it'll just basically dump all the json onto the object. I don't want that overhead obviously.
struct Team:Codable {
var arrConference:[Conference]
private enum CodingKeys: String, CodingKey {
case arrConference = "conferences"
}
struct Conference:Codable {
var conferenceName:String
var conferenceID:String
private enum CodingKeys: String, CodingKey {
case conferenceName = "alias"
case conferenceID = "id"
}
}
}
I guess I am stuck thinking in an old way, but how do you enumerate through the data with a codable?

Swift accessing key from dictionary returning null

I have a dictionary. When I try to access that dictionary, it is returning a null value when it should definately be returning an actual value. I'm stumped. Any help is always appreciated.
if let d = response.result.value {
print(d) //prints correct data
let prices = d["prices"] as? [[String:AnyObject?]]
print(prices) //prints nil
let best_price = prices?[0]
let price = best_price?["price"] as? String
print(price) //prints nil
}
Console:
{
item = {
"item_number" = 57;
image = "http://example.com/tent.jpg";
name = "Small Red Tent";
};
prices = (
{
link = "http://example.com/id=19";
price = "58.15";
rating = "3.64";
"vendor_id" = 50;
},
{
link = "http://example.com/id=50";
price = "58.14";
rating = "5.00";
"vendor_id" = 110;
},
{
link = "http://example.com/id=26";
price = "50.40";
rating = "4.71";
"vendor_id" = 73;
},
{
link = "http://example.com/id=12";
price = "47.16";
rating = "4.00";
"vendor_id" = 1;
},
{
link = "http://example.com/id=13";
price = "45.75";
rating = "3.90";
"vendor_id" = 25;
},
{
link = "http://example.com/id=16";
price = "41.32";
rating = "3.02";
"vendor_id" = 16;
},
{
link = "http://example.com/id=1";
price = "36.59";
rating = "4.84";
"vendor_id" = 51;
},
{
link = "http://example.com/id=2";
price = "36.29";
rating = "3.26";
"vendor_id" = 43;
},
{
link = "http://example.com/id=13";
price = "34.59";
rating = "4.14";
"vendor_id" = 48;
},
{
link = "http://example.com/id=3";
price = "32.00";
rating = "4.29";
"vendor_id" = 53;
},
{
link = "http://example.com/id=4";
price = "24.50";
rating = "4.16";
"vendor_id" = 8;
},
{
link = "http://example.com/id=5";
price = "15.00";
rating = "4.87";
"vendor_id" = 39;
},
{
link = "http://example.com/id=6";
price = "0.00";
rating = "3.00";
"vendor_id" = 65;
}
);
}
nil
nil
So the solution was proposed by Larme solved the problem.
let prices = d["prices"] as? [AnyObject]
Although I never figured out why casting d["prices"] as? [[String:AnyObject?]] wouldn't also work.

Load Specific data from JSON with Random Values Swift

I am using firebase and I am trying to retrieve data from Firebase Database which is working well however when I call "postDict" I get.
["-KPZAOg58kUdqwYMzlDJ":
{
description = jpeg;
listingImageURL = "https://firebasestorage.googleapis.com/v0/b/hype-central.appspot.com/o/lidsafstings%2FC73FdfB8A0-968df7-44DB-B96B-A10DC1E3A2B7.png?alt=media&token=b6e296f2-8854-4b76-9bfc-470dfd69d11f2f";
location = jpeg;
price = 54;
title = jpeg;
userDisplayName = "Brandon YOIO";
userid = pRuwvL7WyzQpY0G22ZLYCmTTemB3;
},
"-KPZ0yLhcfLvP9YWNjbC": {
description = "Description ofvaroe";
listingImageURL = "https://firebadfasestorage.googleapis.com/v0/b/hype-central.appspot.com/o/listings%2F0ACdasfCD645-2E2C-4936-B3DF-37EC55AA0157.png?alt=media&token=b321dasff42f-75b5-4eb3-b129-b0a902cc5926";
location = Vancouver;
price = 34;
title = eclipse;
userDisplayName = "Brandon YOIO";
userid = pRuwvL7WyzQpY0G22ZLYCmTTemB3;
},
"-KPoCsNS63JZdbTJIdaP": {
description = Brandon;
listingImageURL = "https://firebadasfsestorage.googleapis.com/v0/b/hype-central.appspot.com/o/listings%2FOptional(%22pRuwvL7WyzQpY0G22ZLYCmTTemB3%22)%2F3EACE28E-D28A-464A-B6D0-FB502E9dafsB4775.jpeg?alt=media&token=1d45bc7b-7273-4d33-8ccd-755f3102a23c";
location = BRANDON;
price = BRANDON;
title = BRANDON;
userDisplayName = "Brandon YOIO";
userid = pRuwvL7WyzQpY0G22ZLYCmTTemB3;
},
"-KP_Y7ug7hwrHtW6VNqV": {
description = "Description ofvaroe";
listingImageURL = "https://firebaseddasfstorage.googleapis.com/v0/b/hype-central.appspot.com/o/listings%2FC5daf7991BA-D7E0-4C8A-96E7-0DB17EEBABD7.jpeg?alt=media&token=efd03b4d-6964-4685-9b48-5ed36a4ceb59";
location = "";
price = "";
title = "";
userDisplayName = "Brandon Mayhew";
userid = pRuwvL7WyzQpY0G22ZLYCmTTemB3;
}]
If I call "postDict["-KPZAOg58kUdqwYMzlDJ"]["title"]" It will print the title which is exactly what I want however how do I get an array of all the titles in this JSON format (not just the title of "-KPZAOg58kUdqwYMzlDJ").
How do I get all the title's?
Use :-
rootRef.observeEventType(.Value, withBlock: {(postDictionary) in
if let postDict = postDictionary.value as? [String:AnyObject]{
for each in postDict as [String:AnyObject]{
let autoID = each.0
rootRef.child(autoID).observeEventType(.Value, withBlock: {(specificPost) in
//RETRIEVE YOUR DATA
})
}
}
})
PS:- I have used rootRef as you have not specified your parent nodes in your JSON structure :)

objectAtIndex in NSDictionary

I am trying to create UITableView from my NSDictionary, but how can I use objectForKey? Convert to NSArray?
I need help.
My dictionary looks like:
**
{
"allow_comments" = 1;
category = 1024194;
"created_at" = "2011-11-17T01:44";
forum = 1005401;
"forum_obj" = {
"created_at" = "2011-09-03 03:04:43.514514";
description = "";
id = 1005401;
name = smartfiction;
shortname = smartfiction;
};
hidden = 0;
id = 474530565;
identifier = (
"2507 http://smartfiction.ru/?p=2507"
);
"num_comments" = 2;
slug = "thread_9714";
title = "\U041e\U0440\U0438\U0444\U043b\U0430\U043c\U043c\U0430. \U042d\U0436\U0435\U043d \U0418\U043e\U043d\U0435\U0441\U043a\U043e";
url = "http://smartfiction.ru/prose/oriflamma/";
}
2011-11-19 10:21:25.992 ARSSReader[3067:15503] id 474530565
2011-11-19 10:21:26.864 ARSSReader[3067:15503] Ответ #2: (
{
author = {
avatar = {
cache = "http://www.gravatar.com/avatar.php?gravatar_id=af6c6f08e213427ad611b00589db00f9&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
permalink = "http://www.gravatar.com/avatar.php?gravatar_id=af6c6f08e213427ad611b00589db00f9&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
};
emailHash = af6c6f08e213427ad611b00589db00f9;
isAnonymous = 1;
name = "S Shv";
profileUrl = "http://disqus.com/guest/af6c6f08e213427ad611b00589db00f9/";
url = "";
};
createdAt = "2011-11-17T22:39:36";
dislikes = 0;
forum = smartfiction;
id = 367003621;
isApproved = 1;
isDeleted = 0;
isEdited = 0;
isFlagged = 0;
isHighlighted = 0;
isJuliaFlagged = 1;
isSpam = 0;
likes = 0;
media = (
);
message = "\U043f\U043e\U0440\U0430\U0437\U0438\U043b\U043e )";
parent = "<null>";
points = 0;
"raw_message" = "\U043f\U043e\U0440\U0430\U0437\U0438\U043b\U043e )";
thread = 474530565;
},
{
author = {
avatar = {
cache = "http://www.gravatar.com/avatar.php?gravatar_id=c1c53088e04a60aab74cd1f149117e69&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
permalink = "http://www.gravatar.com/avatar.php?gravatar_id=c1c53088e04a60aab74cd1f149117e69&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
};
emailHash = c1c53088e04a60aab74cd1f149117e69;
isAnonymous = 1;
name = "3,14";
profileUrl = "http://disqus.com/guest/c1c53088e04a60aab74cd1f149117e69/";
url = "";
};
createdAt = "2011-11-17T02:52:46";
dislikes = 0;
forum = smartfiction;
id = 365544459;
isApproved = 1;
isDeleted = 0;
isEdited = 0;
isFlagged = 0;
isHighlighted = 0;
isJuliaFlagged = 1;
isSpam = 0;
likes = 1;
media = (
);
message = "\U0427\U0438\U0442\U0430\U0442\U044c \U043d\U0430 \U043d\U043e\U0447\U044c \U043f\U0440\U043e\U043a\U0440\U0430\U0441\U0442\U0438\U043d\U0430\U0442\U043e\U0440\U0430\U043c. \U0412\U043f\U0440\U043e\U0447\U0435\U043c, \U043b\U0443\U0447\U0448\U0435 \U0443\U0442\U0440\U043e\U043c.";
parent = "<null>";
points = 1;
"raw_message" = "\U0427\U0438\U0442\U0430\U0442\U044c \U043d\U0430 \U043d\U043e\U0447\U044c \U043f\U0440\U043e\U043a\U0440\U0430\U0441\U0442\U0438\U043d\U0430\U0442\U043e\U0440\U0430\U043c. \U0412\U043f\U0440\U043e\U0447\U0435\U043c, \U043b\U0443\U0447\U0448\U0435 \U0443\U0442\U0440\U043e\U043c.";
thread = 474530565;
}
)
**
It is comments from disqus.com. I want to create dictionaries for all comments and use them to create UITableView cells.
Instead of storing the comments from disqus.com in a dictionary, store each comment in an entry inside an array (it looks like each comment has a block of text you can encapsulate into an object which you can store into an array).
Dictionaries are good for associating values with keys.
Arrays are great for storing lists of objects, much like a list of comments from a disqus site.

Twitter Direct Messages - iPhone

I have been trying to retrieve the direct messages and place them into a timeline. I have been successful at doing so, but it is not the way I intended... I am a bit confused and can not seem to find an answer to the issue.
I receive as many direct messages as I want but I have an issue while placing them in a tableview they all show.
If you know a thing or two about twitter the direct messages is a list of users who sent you messages then you click into one and is shows you the actual messages.
So I have tried using just the "user_id" because in a list of items the log returns is shows the user id and that still does the same thing. The user_id , scrren_name, profile_image_url are all sub catagories of the main dictionary "sender" recipient" but when I place those in the table view I just crash.....
Below is how I parse the objets and they work but I caint seem to do what it is supposed to really do
Any help would be very much obliged!
//_______________________________________________________________
// DirecctMessages Parse
//_______________________________________________________________
-(NSString*)sender {
return [contents objectForKey:#"sender"] ;
}
-(NSString*)sender_id {
return [[contents objectForKey:#"sender"] objectForKey:#"sender_id"] ;
}
-(NSString*)sender_screenName {
return [[contents objectForKey:#"sender"] objectForKey:#"screen_name"] ;
}
-(NSString*)sender_profileImage {
return [[contents objectForKey:#"sender"] objectForKey:#"profile_image_url"] ;
}
This is the log
"created_at" = "Fri Jun 17 03:11:25 +0000 2011";
id = 3279750226;
recipient = {
"contributors_enabled" = false;
"created_at" = "Wed Nov 10 10:58:54 +0000 2010";
"default_profile" = false;
"default_profile_image" = false;
description = "Creator of xQuisite HD, Omega HD, AfterHours-HD, BlueBird-HD, ..a web
and IOS5 http://www.youtube.com/user/FreeAppl3";
"favourites_count" = 1;
"follow_request_sent" = false;
"followers_count" = 935;
following = 1;
"friends_count" = 256;
"geo_enabled" = true;
id = 214019964;
"is_translator" = false;
lang = en;
"listed_count" = 23;
location = "From NY 518 in Houston 281";
name = "Anthony Cornell";
notifications = false;
"profile_background_color" = 131516;
"profile_background_image_url" =
"http://a2.twimg.com/profile_background_images/256254613/top-wrapper-bg.jpg";
"profile_background_tile" = true;
"profile_image_url" =
"http://a2.twimg.com/profile_images/1361674958/Wintboard_200px_normal.png";
"profile_link_color" = 0485db;
"profile_sidebar_border_color" = eeeeee;
"profile_sidebar_fill_color" = efefef;
"profile_text_color" = 0896f5;
"profile_use_background_image" = true;
protected = 0;
"screen_name" = FreeAppl3;
"show_all_inline_media" = false;
"statuses_count" = 6166;
"time_zone" = "";
url = "http://idevicethemes.com";
"utc_offset" = "";
verified = false;
};
"recipient_id" = 214019964;
"recipient_screen_name" = FreeAppl3;
sender = {
"contributors_enabled" = false;
"created_at" = "Tue Jul 27 15:12:30 +0000 2010";
"default_profile" = false;
"default_profile_image" = false;
description = "Currently a private platform..The one place all Geeks meet. One place
to call home. We are not building an army. WE are building a Legion. #bAdGB";
"favourites_count" = 12;
"follow_request_sent" = false;
"followers_count" = 699;
following = 0;
"friends_count" = 126;
"geo_enabled" = false;
id = 171526185;
"is_translator" = false;
lang = en;
"listed_count" = 30;
location = "Houston/U.S.A";
name = bAdGB;
notifications = false;
"profile_background_color" = C0DEED;
"profile_background_image_url" =
"http://a3.twimg.com/profile_background_images/154928929/geek.jpg";
"profile_background_tile" = true;
"profile_image_url" =
"http://a2.twimg.com/profile_images/1320730007/ProfilePhoto_normal.png";
"profile_link_color" = 0084B4;
"profile_sidebar_border_color" = C0DEED;
"profile_sidebar_fill_color" = DDEEF6;
"profile_text_color" = 333333;
"profile_use_background_image" = false;
protected = 0;
"screen_name" = bAdGigabit;
"show_all_inline_media" = false;
"statuses_count" = 3088;
"time_zone" = "Central Time (US & Canada)";
url = "http://www.bAdGB.com";
"utc_offset" = "-21600";
verified = false;
};
"sender_id" = 171526185;
"sender_screen_name" = bAdGigabit;
"source_api_request_type" = 13;
text = "Dude. U should add a function to let the user get push updates on a themer he
subscribes too ";
}
Is it because there is no sender_id inside the sender object? Instead try using the id.