{"id":8082,"date":"2015-11-25T19:32:14","date_gmt":"2015-11-25T19:32:14","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/25\/how-can-i-use-swiftyjson-dictionaryvalue-as-a-usable-string-for-a-uilabel-open-source-projects-swiftyjson-swiftyjson\/"},"modified":"2022-08-30T15:03:02","modified_gmt":"2022-08-30T15:03:02","slug":"how-can-i-use-swiftyjson-dictionaryvalue-as-a-usable-string-for-a-uilabel-open-source-projects-swiftyjson-swiftyjson","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/25\/how-can-i-use-swiftyjson-dictionaryvalue-as-a-usable-string-for-a-uilabel-open-source-projects-swiftyjson-swiftyjson\/","title":{"rendered":"How can I use swiftyJSON dictionaryValue as a usable string for a UILabel?-open source projects SwiftyJSON\/SwiftyJSON"},"content":{"rendered":"<p>I have a <code>makeRequest()<\/code> method inside a UITableViewController with the following code:<\/p>\n<pre><code>    func makeRequest() {\n\n    Alamofire.request(.GET, self.foursquareEndpointURL, parameters: [\n        \/\/\"VENUE_ID\" : self.foursquareVenueID,\n            \"client_id\" : self.foursquareClientID,\n            \"client_secret\" : self.foursquareClientSecret,\n            \"v\" : \"20140806\"\n            ])\n        .responseJSON(options: nil) { (_, _, data, error) -&gt; Void in\n        if error != nil {\n            println(error?.localizedDescription)\n        } else if let data: AnyObject = data {\n            let jObj = JSON(data)\n            if let venue = jObj[\"response\"][\"venue\"].dictionaryValue as [String: JSON]? {\n                self.responseitems = jObj\n                println(\"venue is: \\(venue)\")\n            }\n            dispatch_async(dispatch_get_main_queue()) {\n                self.tableView.reloadData() \/\/ Update UI\n            }\n        }\n    }\n}\n<\/code><\/pre>\n<p>also keep in mind that I have a property <code>var responseitems:JSON = []<\/code><\/p>\n<p><code>println(\"venue is: \\(venue)\")<\/code> prints a nice looking response to console, so I know that is working correctly&#8230;<\/p>\n<p>I also have a custom UITableViewCell class with a <code>bindData()<\/code> method with the following code:<\/p>\n<pre><code>func bindData() {\n    println(\"VenueDetailHeaderCell data did set\")\n    self.venueDetailTitleLabel.text = self.headerInfo?[\"name\"].stringValue\n    let labelData = self.headerInfo?[\"name\"].stringValue\n    println(\"labelData is: \\(labelData)\")\n}\n<\/code><\/pre>\n<p>As you can see, I am attempting to set a UILabel&#8217;s text to the [&#8220;name&#8221;].stringValue in the JSON response. However, when I <code>println(\"labelData is: \\(labelData)\")<\/code> I get console output of labelData is: Optional(&#8220;&#8221;) which is obviously empty.<\/p>\n<p>Here&#8217;s a screenshot of what I&#8217;m trying to grab<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/CRUKS.jpg\" \/><\/p>\n<p>What am I doing wrong here and how can I grab the name of the venue and assign my UILabel to it?<\/p>\n<p>UPDATE:<\/p>\n<p>I tried the following code<\/p>\n<pre><code>let labelData = self.headerInfo?[\"name\"].error\n    println(\"labelData is: \\(labelData)\")\n<\/code><\/pre>\n<p>And get a console output of: &#8220;Error Domain=SwiftyJSONErrorDomain Code=901 &#8220;Array[0] failure, It is not an array&#8221; UserInfo=0x7fd6d9f7dc10 {NSLocalizedDescription=Array[0] failure, It is not an array}&#8221; If that is of use to anyone. I am really confused here&#8230; Any ideas?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a makeRequest() method inside a UITableViewController with the following code: func makeRequest() { Alamofire.request(.GET, self.foursquareEndpointURL, parameters: [ \/\/&#8221;VENUE_ID&#8221; : self.foursquareVenueID, &#8220;client_id&#8221; : self.foursquareClientID, &#8220;client_secret&#8221; : self.foursquareClientSecret, &#8220;v&#8221; : &#8220;20140806&#8221; ]) .responseJSON(options: nil) { (_, _, data, error) -&gt; Void in if error != nil { println(error?.localizedDescription) } else if let data: AnyObject = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8082","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8082","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=8082"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8082\/revisions"}],"predecessor-version":[{"id":8640,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8082\/revisions\/8640"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=8082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=8082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=8082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}