Having trouble with a json-xcode/swiftHow do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?How can I pretty-print JSON using JavaScript?Parse JSON in JavaScript?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?Swift IOS Reading JSON from urlHow to get formatted json from curl request?

Does a code snippet compile? Or does it get compiled?

What method to use in a batch apex in order to get authentication token from a remote server?

Geodesic preserving diffeomorphisms of constant curvature spaces

In Pokémon Go, why does one of my Pikachu have an option to evolve, but another one doesn't?

In a topological space if there exists a loop that cannot be contracted to a point does there exist a simple loop that cannot be contracted also?

How can I tell if a flight itinerary is fake?

show stdout containing n with line breaks

How to use grep to search through the --help output?

Looking for a new job because of relocation - is it okay to tell the real reason?

Word or idiom defining something barely functional

Iterating through sub-element `sections` of GeoJSON on a Leaflet map?

Generator for parity?

Non-OR journals which regularly publish OR research

What does Apple mean by "This may decrease battery life"?

Why are Gatwick's runways too close together?

Are there any differences in causality between linear and logistic regression?

How many different ways are there to checkmate in the early game?

How do Mogwai reproduce?

Was this a rapid SCHEDULED disassembly? How was it done?

Why did the RAAF procure the F/A-18 despite being purpose-built for carriers?

As a 16 year old, how can I keep my money safe from my mother?

Optimal way to extract "positive part" of a multivariate polynomial

During the Space Shuttle Columbia Disaster of 2003, Why Did The Flight Director Say, "Lock the doors."?

Why do oscilloscopes use SMPS instead of linear power supply?



Having trouble with a json-xcode/swift


How do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?How can I pretty-print JSON using JavaScript?Parse JSON in JavaScript?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?Swift IOS Reading JSON from urlHow to get formatted json from curl request?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-3
















I am trying to add values from what
was printed in the json shown by my code
to specific arrays. For example I want
the lat / lng /name from the JSon file and
add it to an array. How would I go about doing this
? I am new to swift and would appreciate the help.
My Json code is in the comments! Thanks



func getBurritosInArea() 
let keyword:String = "burrito"
let urlString =
"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=(latitude),(longitude)&&fields=formatted_address,name,rating&radius=1500&type=restaurant&keyword=(apikey)"
guard let request = URL(string:urlString) else return
let task = URLSession.shared.dataTask(with: request) (data, response, error) in
guard let data = data, error == nil,
let json = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers),
let results = json as? [String: Any] else //error handling
return

if let placeResults = results["results"] as? [[String: Any]]
for placeResult in results
print(placeResult)






}
json code:
viewport =
northeast =
lat = "40.74642527989272";
lng = "-73.97449797010727"; ;
southwest =
lat = "40.74372562010728";
lng = "-73.97719762989271"; ;
;
};
icon = "maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png"; id = c884c332c5cc1578d0c1d4d7f4d4ad451358c9e6;
name = "Baby Bo's Cantina"; "opening_hours" = "open_now" = 1; ;










share|improve this question


























  • please put the code in your post, not the comments

    – Jodast
    Mar 27 at 0:24











  • any help would really be appreciated!

    – Plank24
    Mar 27 at 2:16

















-3
















I am trying to add values from what
was printed in the json shown by my code
to specific arrays. For example I want
the lat / lng /name from the JSon file and
add it to an array. How would I go about doing this
? I am new to swift and would appreciate the help.
My Json code is in the comments! Thanks



func getBurritosInArea() 
let keyword:String = "burrito"
let urlString =
"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=(latitude),(longitude)&&fields=formatted_address,name,rating&radius=1500&type=restaurant&keyword=(apikey)"
guard let request = URL(string:urlString) else return
let task = URLSession.shared.dataTask(with: request) (data, response, error) in
guard let data = data, error == nil,
let json = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers),
let results = json as? [String: Any] else //error handling
return

if let placeResults = results["results"] as? [[String: Any]]
for placeResult in results
print(placeResult)






}
json code:
viewport =
northeast =
lat = "40.74642527989272";
lng = "-73.97449797010727"; ;
southwest =
lat = "40.74372562010728";
lng = "-73.97719762989271"; ;
;
};
icon = "maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png"; id = c884c332c5cc1578d0c1d4d7f4d4ad451358c9e6;
name = "Baby Bo's Cantina"; "opening_hours" = "open_now" = 1; ;










share|improve this question


























  • please put the code in your post, not the comments

    – Jodast
    Mar 27 at 0:24











  • any help would really be appreciated!

    – Plank24
    Mar 27 at 2:16













-3












-3








-3









I am trying to add values from what
was printed in the json shown by my code
to specific arrays. For example I want
the lat / lng /name from the JSon file and
add it to an array. How would I go about doing this
? I am new to swift and would appreciate the help.
My Json code is in the comments! Thanks



func getBurritosInArea() 
let keyword:String = "burrito"
let urlString =
"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=(latitude),(longitude)&&fields=formatted_address,name,rating&radius=1500&type=restaurant&keyword=(apikey)"
guard let request = URL(string:urlString) else return
let task = URLSession.shared.dataTask(with: request) (data, response, error) in
guard let data = data, error == nil,
let json = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers),
let results = json as? [String: Any] else //error handling
return

if let placeResults = results["results"] as? [[String: Any]]
for placeResult in results
print(placeResult)






}
json code:
viewport =
northeast =
lat = "40.74642527989272";
lng = "-73.97449797010727"; ;
southwest =
lat = "40.74372562010728";
lng = "-73.97719762989271"; ;
;
};
icon = "maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png"; id = c884c332c5cc1578d0c1d4d7f4d4ad451358c9e6;
name = "Baby Bo's Cantina"; "opening_hours" = "open_now" = 1; ;










share|improve this question

















I am trying to add values from what
was printed in the json shown by my code
to specific arrays. For example I want
the lat / lng /name from the JSon file and
add it to an array. How would I go about doing this
? I am new to swift and would appreciate the help.
My Json code is in the comments! Thanks



func getBurritosInArea() 
let keyword:String = "burrito"
let urlString =
"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=(latitude),(longitude)&&fields=formatted_address,name,rating&radius=1500&type=restaurant&keyword=(apikey)"
guard let request = URL(string:urlString) else return
let task = URLSession.shared.dataTask(with: request) (data, response, error) in
guard let data = data, error == nil,
let json = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers),
let results = json as? [String: Any] else //error handling
return

if let placeResults = results["results"] as? [[String: Any]]
for placeResult in results
print(placeResult)






}
json code:
viewport =
northeast =
lat = "40.74642527989272";
lng = "-73.97449797010727"; ;
southwest =
lat = "40.74372562010728";
lng = "-73.97719762989271"; ;
;
};
icon = "maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png"; id = c884c332c5cc1578d0c1d4d7f4d4ad451358c9e6;
name = "Baby Bo's Cantina"; "opening_hours" = "open_now" = 1; ;







json swift xcode url






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 7:46









vadian

169k20 gold badges185 silver badges207 bronze badges




169k20 gold badges185 silver badges207 bronze badges










asked Mar 27 at 0:07









Plank24Plank24

11 bronze badge




11 bronze badge















  • please put the code in your post, not the comments

    – Jodast
    Mar 27 at 0:24











  • any help would really be appreciated!

    – Plank24
    Mar 27 at 2:16

















  • please put the code in your post, not the comments

    – Jodast
    Mar 27 at 0:24











  • any help would really be appreciated!

    – Plank24
    Mar 27 at 2:16
















please put the code in your post, not the comments

– Jodast
Mar 27 at 0:24





please put the code in your post, not the comments

– Jodast
Mar 27 at 0:24













any help would really be appreciated!

– Plank24
Mar 27 at 2:16





any help would really be appreciated!

– Plank24
Mar 27 at 2:16












1 Answer
1






active

oldest

votes


















0














Hi Please try below code,
First Create an Array Named aryDict,



func getBurritosInArea()

guard let url = URL(string: "your url") else return
let task = URLSession.shared.dataTask(with: url) (data, response, error) in
guard let dataResponse = data,
error == nil else
print(error?.localizedDescription ?? "Response Error")
return
do
//here dataResponse received from a network request
let jsonResponse = try JSONSerialization.jsonObject(with:
dataResponse, options: []) as? NSArray
// print(jsonResponse?.value(forKey: STR_NAME) as Any )

let array = NSArray.init(array: jsonResponse ?? [])
var aryDict = NSMutableArray.init(array: array)
// self.tblView.reloadData()
print(aryDict)
catch let parsingError
print("Error", parsingError)


task.resume()






share|improve this answer

























  • Hey man, I appreciate you taking the time to respond but it doesnt seem to be working. I tested it out using a url that for sure worked. The method didnt print anything out. Please let me know how I should approach this! Again, thank you for the help so far.

    – Plank24
    Mar 27 at 18:35











  • It prints out emptry array

    – Plank24
    Mar 27 at 18:38











  • Can you please provide me the URL of API

    – vijay kahar
    Mar 27 at 18:38











  • maps.googleapis.com/maps/api/place/nearbysearch/…)

    – Plank24
    Mar 28 at 18:20











  • thanks again for the help i really appreciate it

    – Plank24
    Mar 28 at 21:06










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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367923%2fhaving-trouble-with-a-json-xcode-swift%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Hi Please try below code,
First Create an Array Named aryDict,



func getBurritosInArea()

guard let url = URL(string: "your url") else return
let task = URLSession.shared.dataTask(with: url) (data, response, error) in
guard let dataResponse = data,
error == nil else
print(error?.localizedDescription ?? "Response Error")
return
do
//here dataResponse received from a network request
let jsonResponse = try JSONSerialization.jsonObject(with:
dataResponse, options: []) as? NSArray
// print(jsonResponse?.value(forKey: STR_NAME) as Any )

let array = NSArray.init(array: jsonResponse ?? [])
var aryDict = NSMutableArray.init(array: array)
// self.tblView.reloadData()
print(aryDict)
catch let parsingError
print("Error", parsingError)


task.resume()






share|improve this answer

























  • Hey man, I appreciate you taking the time to respond but it doesnt seem to be working. I tested it out using a url that for sure worked. The method didnt print anything out. Please let me know how I should approach this! Again, thank you for the help so far.

    – Plank24
    Mar 27 at 18:35











  • It prints out emptry array

    – Plank24
    Mar 27 at 18:38











  • Can you please provide me the URL of API

    – vijay kahar
    Mar 27 at 18:38











  • maps.googleapis.com/maps/api/place/nearbysearch/…)

    – Plank24
    Mar 28 at 18:20











  • thanks again for the help i really appreciate it

    – Plank24
    Mar 28 at 21:06















0














Hi Please try below code,
First Create an Array Named aryDict,



func getBurritosInArea()

guard let url = URL(string: "your url") else return
let task = URLSession.shared.dataTask(with: url) (data, response, error) in
guard let dataResponse = data,
error == nil else
print(error?.localizedDescription ?? "Response Error")
return
do
//here dataResponse received from a network request
let jsonResponse = try JSONSerialization.jsonObject(with:
dataResponse, options: []) as? NSArray
// print(jsonResponse?.value(forKey: STR_NAME) as Any )

let array = NSArray.init(array: jsonResponse ?? [])
var aryDict = NSMutableArray.init(array: array)
// self.tblView.reloadData()
print(aryDict)
catch let parsingError
print("Error", parsingError)


task.resume()






share|improve this answer

























  • Hey man, I appreciate you taking the time to respond but it doesnt seem to be working. I tested it out using a url that for sure worked. The method didnt print anything out. Please let me know how I should approach this! Again, thank you for the help so far.

    – Plank24
    Mar 27 at 18:35











  • It prints out emptry array

    – Plank24
    Mar 27 at 18:38











  • Can you please provide me the URL of API

    – vijay kahar
    Mar 27 at 18:38











  • maps.googleapis.com/maps/api/place/nearbysearch/…)

    – Plank24
    Mar 28 at 18:20











  • thanks again for the help i really appreciate it

    – Plank24
    Mar 28 at 21:06













0












0








0







Hi Please try below code,
First Create an Array Named aryDict,



func getBurritosInArea()

guard let url = URL(string: "your url") else return
let task = URLSession.shared.dataTask(with: url) (data, response, error) in
guard let dataResponse = data,
error == nil else
print(error?.localizedDescription ?? "Response Error")
return
do
//here dataResponse received from a network request
let jsonResponse = try JSONSerialization.jsonObject(with:
dataResponse, options: []) as? NSArray
// print(jsonResponse?.value(forKey: STR_NAME) as Any )

let array = NSArray.init(array: jsonResponse ?? [])
var aryDict = NSMutableArray.init(array: array)
// self.tblView.reloadData()
print(aryDict)
catch let parsingError
print("Error", parsingError)


task.resume()






share|improve this answer













Hi Please try below code,
First Create an Array Named aryDict,



func getBurritosInArea()

guard let url = URL(string: "your url") else return
let task = URLSession.shared.dataTask(with: url) (data, response, error) in
guard let dataResponse = data,
error == nil else
print(error?.localizedDescription ?? "Response Error")
return
do
//here dataResponse received from a network request
let jsonResponse = try JSONSerialization.jsonObject(with:
dataResponse, options: []) as? NSArray
// print(jsonResponse?.value(forKey: STR_NAME) as Any )

let array = NSArray.init(array: jsonResponse ?? [])
var aryDict = NSMutableArray.init(array: array)
// self.tblView.reloadData()
print(aryDict)
catch let parsingError
print("Error", parsingError)


task.resume()







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 27 at 10:20









vijay kaharvijay kahar

2379 bronze badges




2379 bronze badges















  • Hey man, I appreciate you taking the time to respond but it doesnt seem to be working. I tested it out using a url that for sure worked. The method didnt print anything out. Please let me know how I should approach this! Again, thank you for the help so far.

    – Plank24
    Mar 27 at 18:35











  • It prints out emptry array

    – Plank24
    Mar 27 at 18:38











  • Can you please provide me the URL of API

    – vijay kahar
    Mar 27 at 18:38











  • maps.googleapis.com/maps/api/place/nearbysearch/…)

    – Plank24
    Mar 28 at 18:20











  • thanks again for the help i really appreciate it

    – Plank24
    Mar 28 at 21:06

















  • Hey man, I appreciate you taking the time to respond but it doesnt seem to be working. I tested it out using a url that for sure worked. The method didnt print anything out. Please let me know how I should approach this! Again, thank you for the help so far.

    – Plank24
    Mar 27 at 18:35











  • It prints out emptry array

    – Plank24
    Mar 27 at 18:38











  • Can you please provide me the URL of API

    – vijay kahar
    Mar 27 at 18:38











  • maps.googleapis.com/maps/api/place/nearbysearch/…)

    – Plank24
    Mar 28 at 18:20











  • thanks again for the help i really appreciate it

    – Plank24
    Mar 28 at 21:06
















Hey man, I appreciate you taking the time to respond but it doesnt seem to be working. I tested it out using a url that for sure worked. The method didnt print anything out. Please let me know how I should approach this! Again, thank you for the help so far.

– Plank24
Mar 27 at 18:35





Hey man, I appreciate you taking the time to respond but it doesnt seem to be working. I tested it out using a url that for sure worked. The method didnt print anything out. Please let me know how I should approach this! Again, thank you for the help so far.

– Plank24
Mar 27 at 18:35













It prints out emptry array

– Plank24
Mar 27 at 18:38





It prints out emptry array

– Plank24
Mar 27 at 18:38













Can you please provide me the URL of API

– vijay kahar
Mar 27 at 18:38





Can you please provide me the URL of API

– vijay kahar
Mar 27 at 18:38













maps.googleapis.com/maps/api/place/nearbysearch/…)

– Plank24
Mar 28 at 18:20





maps.googleapis.com/maps/api/place/nearbysearch/…)

– Plank24
Mar 28 at 18:20













thanks again for the help i really appreciate it

– Plank24
Mar 28 at 21:06





thanks again for the help i really appreciate it

– Plank24
Mar 28 at 21:06








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367923%2fhaving-trouble-with-a-json-xcode-swift%23new-answer', 'question_page');

);

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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript