{"id":654,"date":"2016-11-03T16:20:00","date_gmt":"2016-11-03T16:20:00","guid":{"rendered":"http:\/\/jonescarvalho.com\/Blog\/?p=654"},"modified":"2020-05-13T20:50:12","modified_gmt":"2020-05-13T23:50:12","slug":"swift-dados-em-json-e-dicionarios","status":"publish","type":"post","link":"https:\/\/jonescarvalho.com\/Blog\/?p=654","title":{"rendered":"Swift &#8211; Dados em Json e Dicion\u00e1rios"},"content":{"rendered":"<p>Exemplo simples de recuperar objetos json e manipular dentro do app iOS.<\/p>\n<p>Primeiramente precisamos adicionar no info.plist uma chave para liberar acesso http.<\/p>\n<p>Chave: <strong>NSAppTransportSecurity, NSAllowsArbitraryLoads<\/strong><\/p>\n<p>Type: <strong>Boolean<\/strong><\/p>\n<p>Value: <strong>YES<\/strong><\/p>\n<p>Agora o c\u00f3digo<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"swift\">override func viewDidLoad() {\n\nsuper.viewDidLoad()\n\nlet url = NSURL(string: \"http:\/\/www.seuURLQueRetornaJson.com\")\n\nlet task = NSURLSession.sharedSession().dataTaskWithURL(url) {\n(data, response, error) - &gt; Void in\n\nif\nlet urlContent = data {\n\ndo {\n\nlet jsonResult =\ntry NSJSONSerialization.JSONObjectWithData(urlContent, options: NSJSONReadingOptions.MutableContainers)\n\nprint(jsonResult[\"chaveJson\"])\n\n}\ncath {\n\nprint(\"JSON Serialization failed\")\n\n}\n\n}\n\n}\n\ntask.resume()\n\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Exemplo simples de recuperar objetos json e manipular dentro do app iOS. Primeiramente [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[57,40,56,39],"class_list":["post-654","post","type-post","status-publish","format-standard","hentry","category-dicas","tag-get","tag-ios","tag-json","tag-swift"],"_links":{"self":[{"href":"https:\/\/jonescarvalho.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/654"}],"collection":[{"href":"https:\/\/jonescarvalho.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jonescarvalho.com\/Blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jonescarvalho.com\/Blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jonescarvalho.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=654"}],"version-history":[{"count":5,"href":"https:\/\/jonescarvalho.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/654\/revisions"}],"predecessor-version":[{"id":843,"href":"https:\/\/jonescarvalho.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/654\/revisions\/843"}],"wp:attachment":[{"href":"https:\/\/jonescarvalho.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jonescarvalho.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jonescarvalho.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}