I've managed to export the below data, multiplied by several hundred, into an NSDictionary. I now need to build out a way to put this data into Tinder style app. Can anyone advise how I can get my app to pull out the data against Key "Title" for various indexes. Currently it pulls out 45 records of data containing that one Title as there are 45 keys in my data set.
{
AttachmentFiles = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/AttachmentFiles";
};
};
Attachments = 0;
AuthorId = 22;
AverageRating = "<null>";
BestAnswerId = "<null>";
Body = "We need to think xyz";
CategoriesLookupId = 16;
Community = "<null>";
ContentType = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/ContentType";
};
};
ContentTypeId = 0x01200200C5BB1FEE2601B9439CD527C288D85A7B;
Created = "2014-03-21T08:37:33Z";
DescendantLikesCount = 8;
DescendantRatingsCount = "<null>";
DiscussionLastUpdated = "2014-06-19T12:57:58Z";
EditorId = 96;
EmailSender = "<null>";
FieldValuesAsHtml = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/FieldValuesAsHtml";
};
};
FieldValuesAsText = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/FieldValuesAsText";
};
};
FieldValuesForEdit = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/FieldValuesForEdit";
};
};
File = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/File";
};
};
FileSystemObjectType = 1;
FilterCategory = "<null>";
FirstUniqueAncestorSecurableObject = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/FirstUniqueAncestorSecurableObject";
};
};
Folder = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/Folder";
};
};
GUID = "28144fd4-84b0-434b-9e99-01d939e6a773";
Has20likes = "<null>";
ID = 3;
Id = 3;
IsFeatured = 0;
IsIdeaCreated = "<null>";
IsQuestion = 0;
LastReplyById = 49;
LikesCount = 5;
MemberLookupId = 7;
Modified = "2015-03-11T15:25:20Z";
"OData__UIVersionString" = "2.0";
ParentItemEditorId = "<null>";
ParentItemID = "<null>";
ParentList = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/ParentList";
};
};
Popularity = "7.23632608186099";
RatingCount = "<null>";
RoleAssignments = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/RoleAssignments";
};
};
StepChangePillar = "<null>";
Title = "JIRA Governance";
"__metadata" = {
etag = "\"14\"";
id = "Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)";
type = "SP.Data.Community_x0020_DiscussionListItem";
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)";
};
},
Thanks
You should have an array of dictionaries correct?
If so this should work:
NSInteger index = 0; //You can set this to the current page of your scroll view
NSArray * items = /* YOUR ARRAY OF DICTIONARIES */;
NSDictionary * dict = [items objectAtIndex:index];
NSString * title = [dict objectForKey:#"Title"];
You might also consider making a subclass of NSObject and building in a parser for your dictionary so you can access the variables with strong types.
Related
please tell me how to unwrap this josn response because of optional json i am not able to parse in label
i have tried my best but i am new to swift so i can't get it to unwrap the optional json
response::
Optional(<__NSArrayM 0x600000848340>(
{
contributors = "";
coordinates = "";
"created_at" = "Thu Jul 12 11:49:57 +0000 2018";
entities = {
hashtags = (
);
media = (
{
"display_url" = "pic.twitter.com/IJtq6aLM7K";
"expanded_url" = "";
id = 1017375504448479232;
"id_str" = 1017375504448479232;
indices = (
12,
35
);
"media_url" = "";
"media_url_https" = "";
sizes = {
large = {
h = 1820;
resize = fit;
w = 2048;
};
medium = {
h = 1067;
resize = fit;
w = 1200;
};
small = {
h = 604;
resize = fit;
w = 680;
};
thumb = {
h = 150;
resize = crop;
w = 150;
};
};
type = photo;
url = "";
}
);
symbols = (
);
urls = (
);
"user_mentions" = (
);
};
"extended_entities" = {
media = (
{
"display_url" = "pic.twitter.com/IJtq6aLM7K";
"expanded_url" = "";
id = 1017375504448479232;
"id_str" = 1017375504448479232;
indices = (
12,
35
);
"media_url" = "";
"media_url_https" = "";
sizes = {
large = {
h = 1820;
resize = fit;
w = 2048;
};
medium = {
h = 1067;
resize = fit;
w = 1200;
};
small = {
h = 604;
resize = fit;
w = 680;
};
thumb = {
h = 150;
resize = crop;
w = 150;
};
};
type = photo;
url = "";
}
);
};
"favorite_count" = 0;
favorited = 0;
geo = "";
id = 1017375507174719488;
"id_str" = 1017375507174719488;
"in_reply_to_screen_name" = "";
"in_reply_to_status_id" = "";
"in_reply_to_status_id_str" = "";
"in_reply_to_user_id" = "";
"in_reply_to_user_id_str" = "";
"is_quote_status" = 0;
lang = fr;
place = "";
"possibly_sensitive" = 0;
"retweet_count" = 0;
retweeted = 0;
source = "";
text = "Tweet Tweet ";
truncated = 0;
user = {
"contributors_enabled" = 0;
"created_at" = "Tue Mar 27 05:14:33 +0000 2018";
"default_profile" = 1;
"default_profile_image" = 0;
description = "";
entities = {
description = {
urls = (
);
};
};
"favourites_count" = 3;
"follow_request_sent" = 0;
"followers_count" = 1;
following = 0;
"friends_count" = 0;
"geo_enabled" = 1;
"has_extended_profile" = 0;
id = 978500498897563648;
"id_str" = 978500498897563648;
"is_translation_enabled" = 0;
"is_translator" = 0;
lang = en;
"listed_count" = 0;
location = "";
name = Mike;
notifications = 0;
"profile_background_color" = F5F8FA;
"profile_background_image_url" = "";
"profile_background_image_url_https" = "";
"profile_background_tile" = 0;
"profile_image_url" = "";
"profile_image_url_https" = "";
"profile_link_color" = 1DA1F2;
"profile_sidebar_border_color" = C0DEED;
"profile_sidebar_fill_color" = DDEEF6;
"profile_text_color" = 333333;
"profile_use_background_image" = 1;
protected = 0;
"screen_name" = Mike50430315;
"statuses_count" = 13;
"time_zone" = "";
"translator_type" = none;
url = "";
"utc_offset" = "";
verified = 0;
};
}
because of this i am getting nil value in all like name text retweet please tell me how to solve this
var timeline = (FHSTwitterEngine.shared().getTimelineForUser(FHSTwitterEngine.shared().authenticatedUsername, isID: true, count: 10), terminator: "")
from this line i am getting whole response
and then i have on array i create and store in to array like below
var serviceData = [AnyObject]()
let timelinedata = [timeline] as [AnyObject]
serviceData = (timelinedata)
print(serviceData)
In general, anything optional can be unwrapped like so:
let optionalValue: String? = "Hello, this is optional!"
if let noLongerOptional = optionalValue {
print("\(noLongerOptional) no its not! ahah")
}
Edit: more specific example...
Assuming you have a variable 'myJson' which hold your optional value... and you did:
print("\(myJson)")
You can solve this by:
if let validJson = myJson {
print("\(validJson)")
}
Edit 2: ... FHSTwitter... (updated.... this is getting long)
let twitterEngine = FHSTwitterEngine.sharedEngine()
let twitterUser = twitterEngine.authenticatedID
let timeline = twitterEngine.getTimelineForUser(twitterUser, isID: true, count: 10)
According to FHSTwitterEngine docs... getTimelineForUser() will return either a NSError or an array of Tweets.
so...
if let error = timeline as? Error {
print("Oops, looks like something went wrong: \(error)")
} else {
if let tweets = timeline as? [Any] {
for tweet in tweets {
print("This is a tweet: \(tweet)")
}
}
}
If you have any more trouble using FHSTwitterEngine, I suggest you play with: https://github.com/natesymer/FHSTwitterEngine/tree/master/FHSTwitterEngineDemoSwift/Demo-Swift
Or open a support ticket with the FHSTwitterEngine developer(s) at: https://github.com/natesymer/FHSTwitterEngine/issues
Good Luck!
How can I populate a few UILabels on a ViewController from the JSON object I receive from a previously passed id parameter? I get the response from the server but, I don't know how to populate the key/value pairs to a UILabel.
The JSON response I get is:
{
product = {
attributes = (
);
"average_rating" = "0.00";
backordered = 0;
"backorders_allowed" = 0;
"button_text" = "";
"catalog_visibility" = visible;
categories = (
);
"created_at" = "2016-02-23T05:00:55Z";
"cross_sell_ids" = (
);
description = "<p>Microsoft Office</p>\n";
dimensions = {
height = "";
length = "";
unit = in;
width = "";
};
"download_expiry" = 0;
"download_limit" = 0;
"download_type" = "";
downloadable = 0;
downloads = (
);
featured = 0;
"featured_src" = "https://qashop.taxometry.com/wordpressv4/wp-content/uploads/2016/02/softwarecontract-150x150.jpg";
"grouped_products" = (
);
id = 15;
images = (
{
alt = "";
"created_at" = "2016-02-23T05:01:35Z";
id = 16;
position = 0;
src = "https://qashop.taxometry.com/wordpressv4/wp-content/uploads/2016/02/softwarecontract-150x150.jpg";
title = "softwarecontract-150×150";
"updated_at" = "2016-02-23T05:01:35Z";
}
);
"in_stock" = 1;
"managing_stock" = 0;
"menu_order" = 0;
"on_sale" = 1;
parent = (
);
"parent_id" = 0;
permalink = "https://qashop.taxometry.com/wordpressv4/product/software-contract/";
price = 25;
"price_html" = "<del><span class=\"amount\">$30.00</span></del> <ins><span class=\"amount\">$25.00</span></ins>";
"product_url" = "";
"purchase_note" = "";
purchaseable = 1;
"rating_count" = 0;
"regular_price" = 30;
"related_ids" = (
);
"reviews_allowed" = 1;
"sale_price" = 25;
"shipping_class" = "";
"shipping_class_id" = "<null>";
"shipping_required" = 1;
"shipping_taxable" = 1;
"short_description" = "";
sku = 2370;
"sold_individually" = 0;
status = publish;
"stock_quantity" = "<null>";
tags = (
);
"tax_class" = "";
"tax_status" = taxable;
taxable = 1;
title = "Software Contract";
"total_sales" = 5;
type = simple;
"updated_at" = "2016-02-23T05:01:41Z";
"upsell_ids" = (
);
variations = (
);
virtual = 0;
visible = 1;
weight = "<null>";
};
}
Try this - > First
then Second
I have Json object like this :
{
CO = 1;
CUABR = "<null>";
CUNO = "<null>";
DIV = 2;
DLDAT = 1020923;
SALID = "<null>";
"form_number" = MM23000;
type = VHNO;
},
{
CO = 1;
CUABR = "<null>";
CUNO = "<null>";
DIV = 2;
DLDAT = 1020923;
SALID = "<null>";
"form_number" = MM23001;
type = VHNO;
},
{
CO = 1;
CUABR = "<null>";
CUNO = "<null>";
DIV = 2;
DLDAT = 1020924;
SALID = "<null>";
"form_number" = MM23002;
type = VHNO;
},
{
CO = 1;
CUABR = "\U53f0\U5316\U65b0\U6e2f";
CUNO = FCFC3;
DIV = 2;
DLDAT = 1020924;
SALID = M;
"form_number" = MM23003;
type = VHNO;
}
}
then I need to remove json array content null dictionary key value to sort like this:
{
CO = 1;
CUABR = "\U53f0\U5316\U65b0\U6e2f";
CUNO = FCFC3;
DIV = 2;
DLDAT = 1020924;
SALID = M;
"form_number" = MM23003;
type = VHNO;
}
}
How should I do?
I would like to know the proper way, should I use nest loop or block?
Thanks for helping.
use this may help you..
NSMutableArray *newarray=[NSMutableArray array];
for (NSDictionary *dictionary in parseArrray)
{
if (dictionary[key] != [NSNull null]) {
[newarray addObject:dictionary];
}
}
i am trying facebook albums integration, used me/albums methods its showing this graph api query: I am getting json format correctly but the thing is i want to retrieve album images one by one and display it in grid view ...please anybody suggest some code or idea...
Results: {
data = (
{
"can_upload" = 1;
count = 2;
"cover_photo" = 1404379296458611;
"created_time" = "2013-10-04T11:35:21+0000";
from = {
id = 100006596624401;
name = "sample";
};
id = 1404366983126509;
link = "https://www.facebook.com/album.php?fbid=1404366983126509&id=100006596624401&aid=1073741827";
name = "Photos";
privacy = custom;
type = app;
"updated_time" = "2013-10-09T07:41:48+0000";
},
{
"can_upload" = 0;
"created_time" = "2013-10-08T10:55:52+0000";
from = {
id = 100006596624401;
name = "sample";
};
id = 1406014439628430;
link = "https://www.facebook.com/album.php?fbid=1406014439628430&id=100006596624401&aid=1073741829";
name = "he Photos";
privacy = custom;
type = app;
"updated_time" = "2013-10-08T11:33:49+0000";
},
{
"can_upload" = 0;
count = 1;
"cover_photo" = 1405547679675106;
"created_time" = "2013-10-07T06:21:36+0000";
from = {
id = 100006596624401;
name = "sample";
};
id = 1405547666341774;
link = "https://www.facebook.com/album.php?fbid=1405547666341774&id=100006596624401&aid=1073741828";
name = test;
privacy = everyone;
type = normal;
"updated_time" = "2013-10-07T06:21:47+0000";
},
{
"can_upload" = 0;
"created_time" = "2013-09-25T05:30:31+0000";
from = {
id = 100006596624401;
name = "sample";
};
id = 1399900213573186;
link = "https://www.facebook.com/album.php?fbid=1399900213573186&id=100006596624401&aid=1073741825";
name = "iOS Photos";
privacy = everyone;
type = app;
"updated_time" = "2013-09-25T06:26:13+0000";
}
);
paging = {
cursors = {
after = "MTM5OTkwMDIxMzU3MzE4Ng==";
before = "MTQwNDM2Njk4MzEyNjUwOQ==";
};
};
{
comments = {
count = 0;
};
"created_time" = "2013-01-23T06:12:43+0000";
from = {
id = 1171029418;
name = "Ilse Anhy";
};
icon = "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif";
id = "1171029418_10200426347839190";
link = "https://www.facebook.com/photo.php?fbid=10200426378279951&set=a.3604514069432.2168112.1171029418&type=1&relevant_count=2";
"object_id" = 10200426378279951;
picture = "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash4/265145_10200426378279951_1504367216_s.jpg";
privacy = {
value = "";
};
"status_type" = "added_photos";
story = "Ilse Anhy added 2 new photos.";
"story_tags" = {
0 = (
{
id = 1171029418;
length = 9;
name = "Ilse Anhy";
offset = 0;
type = user;
}
);
};
type = photo;
"updated_time" = "2013-01-23T06:12:43+0000";
}
In the "story" object it says "Ilse Anhy added 2 new photos."
In the "picture" object it only gives a reference to a single photo. How would I be able to retrieve the other photo?