Fetching And Parsing Data From Json Api In Faster Way in Swift The Next CEO of Stack OverflowParse JSON in C#Parsing JSON with Unix toolsHow to parse JSON in JavaWhy can't Python parse this JSON data?Parse JSON in JavaScript?How to parse JSON using Node.js?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?How do I get ASP.NET Web API to return JSON instead of XML using Chrome?How do I write JSON data to a file?How to call Objective-C code from Swift
How do I solve this limit?
How do I get the green key off the shelf in the Dobby level of Lego Harry Potter 2?
What happens if you roll doubles 3 times then land on "Go to jail?"
How to write the block matrix in LaTex?
How do spells that require an ability check vs. the caster's spell save DC work?
Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?
Customer Requests (Sometimes) Drive Me Bonkers!
Is HostGator storing my password in plaintext?
How to make a software documentation "officially" citable?
When did Lisp start using symbols for arithmetic?
How do we know the LHC results are robust?
What is the difference between "behavior" and "behaviour"?
Why is there a PLL in CPU?
Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables
If the heap is initialized for security, then why is the stack uninitialized?
Why does standard notation not preserve intervals (visually)
Does it take more energy to get to Venus or to Mars?
The King's new dress
How to write papers efficiently when English isn't my first language?
Unreliable Magic - Is it worth it?
What is the purpose of the Evocation wizard's Potent Cantrip feature?
Too much space between section and text in a twocolumn document
What materials would I use to build an underwater city?
Why do professional authors make "consistency" mistakes? And how to avoid them?
Fetching And Parsing Data From Json Api In Faster Way in Swift
The Next CEO of Stack OverflowParse JSON in C#Parsing JSON with Unix toolsHow to parse JSON in JavaWhy can't Python parse this JSON data?Parse JSON in JavaScript?How to parse JSON using Node.js?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?How do I get ASP.NET Web API to return JSON instead of XML using Chrome?How do I write JSON data to a file?How to call Objective-C code from Swift
I working on a IOS project based on json API totally. I have completed my project almost but i have an issue regarding json API response rate, it is very slow and it takes time to load data in tableview. I am looking for a best way to fetch or parse data or load data in tableview quickly or faster.
here is a example of my code
let base_url = "http://saburia.com/"
// guard let url = URL(string: "(base_url)login_verifications?phone=(textView.text ?? "")&device=ios") else return
let ID = UserDefaults.standard.string(forKey: "pos_no") ?? ""
guard let url = URL(string: "http://saburia.com/api?cat_name=1&pos_no=(ID)") else return
URLSession.shared.dataTask(with: url) (data, response, err) in
guard let data = data else return
do
//let fetchedData = try JSONDecoder().decode([uniDpt_list].self, from: data)
let myjson = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as? [Any]
print(myjson)
var sectiontitle : [Any] = []
var catLink : [Any] = []
for game in myjson! as [AnyObject]
// print(game["name"]!!)
sectiontitle.append(game["cat_name"]!!)
catLink.append(game["cat_link"]!)
// print(dptArray)
self.CategoriesSection = sectiontitle as! [String]
self.categoryLink = catLink as! [String]
print(self.categoryLink)
DispatchQueue.main.async
self.myTableView.reloadData()
catch let jsonErr
print("Error serializing json:", jsonErr)
.resume()
ios json swift api
add a comment |
I working on a IOS project based on json API totally. I have completed my project almost but i have an issue regarding json API response rate, it is very slow and it takes time to load data in tableview. I am looking for a best way to fetch or parse data or load data in tableview quickly or faster.
here is a example of my code
let base_url = "http://saburia.com/"
// guard let url = URL(string: "(base_url)login_verifications?phone=(textView.text ?? "")&device=ios") else return
let ID = UserDefaults.standard.string(forKey: "pos_no") ?? ""
guard let url = URL(string: "http://saburia.com/api?cat_name=1&pos_no=(ID)") else return
URLSession.shared.dataTask(with: url) (data, response, err) in
guard let data = data else return
do
//let fetchedData = try JSONDecoder().decode([uniDpt_list].self, from: data)
let myjson = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as? [Any]
print(myjson)
var sectiontitle : [Any] = []
var catLink : [Any] = []
for game in myjson! as [AnyObject]
// print(game["name"]!!)
sectiontitle.append(game["cat_name"]!!)
catLink.append(game["cat_link"]!)
// print(dptArray)
self.CategoriesSection = sectiontitle as! [String]
self.categoryLink = catLink as! [String]
print(self.categoryLink)
DispatchQueue.main.async
self.myTableView.reloadData()
catch let jsonErr
print("Error serializing json:", jsonErr)
.resume()
ios json swift api
What do you mean by “very slow”? You can use the time profiler instrument to see how long each line takes. But the slowness might be the network connection
– Aaron Brager
Mar 8 at 12:55
Its takes a minute to load data mostly.
– hussnain ahmad
Mar 8 at 12:57
I don't know if usingDecodable
is faster or slower but it would definitely improve your code with less casting
– Joakim Danielson
Mar 8 at 12:58
add a comment |
I working on a IOS project based on json API totally. I have completed my project almost but i have an issue regarding json API response rate, it is very slow and it takes time to load data in tableview. I am looking for a best way to fetch or parse data or load data in tableview quickly or faster.
here is a example of my code
let base_url = "http://saburia.com/"
// guard let url = URL(string: "(base_url)login_verifications?phone=(textView.text ?? "")&device=ios") else return
let ID = UserDefaults.standard.string(forKey: "pos_no") ?? ""
guard let url = URL(string: "http://saburia.com/api?cat_name=1&pos_no=(ID)") else return
URLSession.shared.dataTask(with: url) (data, response, err) in
guard let data = data else return
do
//let fetchedData = try JSONDecoder().decode([uniDpt_list].self, from: data)
let myjson = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as? [Any]
print(myjson)
var sectiontitle : [Any] = []
var catLink : [Any] = []
for game in myjson! as [AnyObject]
// print(game["name"]!!)
sectiontitle.append(game["cat_name"]!!)
catLink.append(game["cat_link"]!)
// print(dptArray)
self.CategoriesSection = sectiontitle as! [String]
self.categoryLink = catLink as! [String]
print(self.categoryLink)
DispatchQueue.main.async
self.myTableView.reloadData()
catch let jsonErr
print("Error serializing json:", jsonErr)
.resume()
ios json swift api
I working on a IOS project based on json API totally. I have completed my project almost but i have an issue regarding json API response rate, it is very slow and it takes time to load data in tableview. I am looking for a best way to fetch or parse data or load data in tableview quickly or faster.
here is a example of my code
let base_url = "http://saburia.com/"
// guard let url = URL(string: "(base_url)login_verifications?phone=(textView.text ?? "")&device=ios") else return
let ID = UserDefaults.standard.string(forKey: "pos_no") ?? ""
guard let url = URL(string: "http://saburia.com/api?cat_name=1&pos_no=(ID)") else return
URLSession.shared.dataTask(with: url) (data, response, err) in
guard let data = data else return
do
//let fetchedData = try JSONDecoder().decode([uniDpt_list].self, from: data)
let myjson = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as? [Any]
print(myjson)
var sectiontitle : [Any] = []
var catLink : [Any] = []
for game in myjson! as [AnyObject]
// print(game["name"]!!)
sectiontitle.append(game["cat_name"]!!)
catLink.append(game["cat_link"]!)
// print(dptArray)
self.CategoriesSection = sectiontitle as! [String]
self.categoryLink = catLink as! [String]
print(self.categoryLink)
DispatchQueue.main.async
self.myTableView.reloadData()
catch let jsonErr
print("Error serializing json:", jsonErr)
.resume()
ios json swift api
ios json swift api
edited Mar 8 at 17:59
rmaddy
245k27326389
245k27326389
asked Mar 8 at 12:52
hussnain ahmadhussnain ahmad
248
248
What do you mean by “very slow”? You can use the time profiler instrument to see how long each line takes. But the slowness might be the network connection
– Aaron Brager
Mar 8 at 12:55
Its takes a minute to load data mostly.
– hussnain ahmad
Mar 8 at 12:57
I don't know if usingDecodable
is faster or slower but it would definitely improve your code with less casting
– Joakim Danielson
Mar 8 at 12:58
add a comment |
What do you mean by “very slow”? You can use the time profiler instrument to see how long each line takes. But the slowness might be the network connection
– Aaron Brager
Mar 8 at 12:55
Its takes a minute to load data mostly.
– hussnain ahmad
Mar 8 at 12:57
I don't know if usingDecodable
is faster or slower but it would definitely improve your code with less casting
– Joakim Danielson
Mar 8 at 12:58
What do you mean by “very slow”? You can use the time profiler instrument to see how long each line takes. But the slowness might be the network connection
– Aaron Brager
Mar 8 at 12:55
What do you mean by “very slow”? You can use the time profiler instrument to see how long each line takes. But the slowness might be the network connection
– Aaron Brager
Mar 8 at 12:55
Its takes a minute to load data mostly.
– hussnain ahmad
Mar 8 at 12:57
Its takes a minute to load data mostly.
– hussnain ahmad
Mar 8 at 12:57
I don't know if using
Decodable
is faster or slower but it would definitely improve your code with less casting– Joakim Danielson
Mar 8 at 12:58
I don't know if using
Decodable
is faster or slower but it would definitely improve your code with less casting– Joakim Danielson
Mar 8 at 12:58
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063634%2ffetching-and-parsing-data-from-json-api-in-faster-way-in-swift%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063634%2ffetching-and-parsing-data-from-json-api-in-faster-way-in-swift%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you mean by “very slow”? You can use the time profiler instrument to see how long each line takes. But the slowness might be the network connection
– Aaron Brager
Mar 8 at 12:55
Its takes a minute to load data mostly.
– hussnain ahmad
Mar 8 at 12:57
I don't know if using
Decodable
is faster or slower but it would definitely improve your code with less casting– Joakim Danielson
Mar 8 at 12:58