FAQ Database Discussion Community


Swift JSON add new key to existing dictionary

json,swift,swifty-json
I'm using Alamofire and SwiftyJSON to get and manage data from an API After making my initial request I end up with nested collection of type JSON According to SwiftyJSON I can loop through data like so https://github.com/SwiftyJSON/SwiftyJSON#loop for (key: String, subJson: JSON) in json { //Do something you want...

NSObject does not have a member named Key error

ios,arrays,json,swift,swifty-json
I need to construct a JSON object in the format shown below. { "DeviceCredentials": { "UniqueId": "sample string 1" }, "Handovers": [ { "Occasions": [ { "Id": 1 }, { "Id": 1 } ] } ] } There is a issue though with the Occasions array though. The number of...

Trouble unwrapping JSON Array to a String Value

ios,json,swift,swifty-json
I have been struggling with JSON for a few days. I am trying to create a POST request to my web server for a username, that will return information on said user. I have managed to get the JSON response two ways, but I cannot cast any of the elements...

Apply map to JSON array in swift

swift,dictionary,swifty-json
Using SwiftyJSON I loaded a JSON array with the following structure. [ { "x": 2, "y": 2, "r": 100, "description": {"name":"bob","institution":"NYU","technologies":[]} }, { "x": 4, "y": 4, "r": 200, "description": {"name":"bob","institution":"NYU","technologies":[]} },... ] Problem I want to create an object from each element in this array. My approach let chartPoints:...

Parse JSON array to matrix using map

json,swift,swifty-json
I'm using swiftyJSON. The data looks like the following but not really, there are about 700,000 elements. { "data": [ [ "one", "steak", -0.234 ], [ "cat", "pizza", 1.9812 ] ] } Currently I'm using this let jsonArray:[JSON] = json["data"].arrayValue for ( i=0; i<jsonArray.count; i++ )//number of data points {...

How to retrieve data from file with SwiftyJSON

json,swift,swifty-json
I have added a JSON-file to my file-system where the data is structured like this: { "DDD" : "3D Systems Corporation", "MMM" : "3M Company", "WBAI" : "500.com Limited", "WUBA" : "58.com Inc.", "AHC" : "A.H. Belo Corporation", "ATEN" : "A10 Networks, Inc.", "AAC" : "AAC Holdings, Inc.", "AIR" :...

SwiftyJSON won't parse a JSON string that will later parse with no issue

ios,swift,pubnub,swifty-json
I have the following PubNub delegate methods that are getting called in the exact order as declared below. public func pubnubClient(client: PubNub!, didSubscribeOnChannels channels: NSArray!) { log.info("Subscribed to \(channels.count) channels") PubNub.sendMessage("{\"type\": \"CHAT_MSG\",\"msgId\": \"1233123\",\"text\": \"hello\",\"username\": \"attheodo\",\"uuid\": \"user_1\",\"associatedPlaceId\": 2}", toChannel:pubnubChannels[0]) } public func pubnubClient(client: PubNub!, subscriptionDidFailWithError error: PNError!){...

problems using Grand Central Dispatch IOS Swift Xcode 6.3.1

ios,xcode,multithreading,swift,swifty-json
I'm learning swift now and having hard time understanding the multithreading issues.. specific problem Im having is that i'm loading data from the internet and trying to return an array ("broadcasts") containing this data while using dispatch_async . My problem is that the return execution with the empty array happens...

Swift Alamofire SwiftyJSON Asynchronous/Synchronous Class Methods

swift,asynchronous,synchronous,alamofire,swifty-json
So I currently have the following: class ViewController: UIViewController { class Identity{ let baseUrl = "superSecretURL" var _username: String = "" var _password: String = "" var _apiKey: String = "" init(){ } init(username: String, apiKey: String){ _username = username _apiKey = apiKey } init(username: String, password: String){ _username =...

SwiftyJSON: Update Cells in UITableView from JSON response

ios,json,uitableview,alamofire,swifty-json
I'm pretty new to iOS Development so please be gentle. I am using the Alamofire and SwiftyJSON libraries for a project to get and parse a JSON file that is on a server. I also have used this tutorial to get a UITableView with a few cells "Cell 1" "Cell...

how to add json object to dictionary

swift,alamofire,swifty-json
when i create output with Alamofire using SwiftyJSON Alamofire.request(.POST, "http://localhost:8080/ws/automobile/global/auction/latest/venues").responseJSON() { (request, response, jsonData, error) in var venues = JSON(jsonData!) println(venues) } it appear like this in console { "C2058" : [ "LAA Okayama" ], "C2062" : [ "NAA Osaka" ], "C2035" : [ "JU Ibaraki" ], "C2526" : [...

Create JSON Object from Class in Swift

swift,alamofire,swifty-json
I'm pretty new to iOS development and Swift (so please bear with me). I have a class object defined like this: class LocationPoint { var x: Double var y: Double var orientation: Double init(x: Double, y: Double, orientation: Double) { self.x = x self.y = y self.orientation = orientation }...

returning a value from a function with Alamofire and SwiftyJson

swift,alamofire,swifty-json
I have an app that returns a menu of information (basically menus, menu_headers, and items). I'd like to have something like this: EKMenu.getMenu(menu_id: Int) that would return a menu but I think I would need a completion handler in here. I currently have: class func getMenu(menu_id: Int){ //class func getMenu(menu_id:...

How can I call this function in viewDidLoad() in iOS8

swift,ios8,swifty-json
I want to call this function in viewDidLoad but I don't know how one would do this. Can you please help me? func loginWithFacebook(withcompletionHandler: (success:Bool) ->()){ var permissions : Array = [ "user_location","public_profile"] PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions, { (user: PFUser?, error: NSError?) -> Void in if let user = user { if user.isNew...

Crash in SwiftyJSON during string comparison: swift_unknownRetain

swift,crash,crashlytics,swifty-json
I'm switching on a flag from the server in order to determine what type of object to instantiate. Each type is a subclass of the return type (Snack, in the example.) My guess is that the whole subclass thing is irrelevant to the main issue, but I include it for...

Swiftyjson bundled file

ios,json,swift,uitableview,swifty-json
Ok i have a bundled .json file that I am looking to parse with swifty json. The model I am using in swifty json is a top level object that has an array of objects that each contain values of either strings or ints. I was wondering what code I...

How can i parse to TextField iOS Keychain in Swift?

swift,swifty-json
I saved my account through Locksmith Keychain, everything works fine, right now i need to parse the data stored to a textField, how can i do it please? Here is the code that i use to save my account: let accountsave = Locksmith.saveData(["account": self.txtAccount.text], forUserAccount: "myUserAccount", inService: "myAccount"). Right now...

How to setup SwiftyJSON on my Swift XCode App?

ios,json,xcode,swift,swifty-json
I am want to handle JSON on my Swift XCode app, I am stuck trying to mae SwiftyJSON work the first time. So far I have done what appears in this post, and I can access SwiftyJSON function calls from my code. However, the code inside SwiftyJSON.swift file that I...

Passing along values from 1 function to another in Swift

ios,swift,swifty-json
So I've got 2 functions in this class that I'm working on that need to use the same variable. This variable is filled with a JSON object from the SwiftyJSON framework. I start of instaniating the variable like so: var fooGame : JSON?; Then I fill this bad boy up...

Converting JSON from AlamoFire/SwiftyJSON to Dictionary in Swift/Xcode

xcode,swift,alamofire,swifty-json
My head is going to explode :) - I've been trying to get a JSON String from my server to a Dictionary Value, and I can't get it to work. I'm trying to get (from my Server - this is dynamic and I want my app to be able to...

how to parse this particular json in swift

json,swift,ios8,swifty-json
I am new to Swift and JSON, so please bear with me if this is stupid. I am trying to parse this particular JSON http://jsonplaceholder.typicode.com/users in swift. I am able to get the values of one user by typing http://jsonplaceholder.typicode.com/users/1 , but the problem is, it only provides me the...

How to append new data to an existing JSON array(swiftyJSON)

ios,arrays,json,swift,swifty-json
I have an array of SwiftyJson data that I have declared and filled it with data .The code I'm using to fill the hoge array is this : self.hoge = JSON(data: data!) but I need to append new swiftyJSON data to this hoge array .I noticed hoge array doesn't have...

Swift: How to use library: Alamofire-SwiftyJSON

swift,alamofire,swifty-json
I'm having trouble trying to get this library Alamofire-SwiftyJSON (https://github.com/SwiftyJSON/Alamofire-SwiftyJSON) to work. I created a new project and downloaded the Alamofire-SwiftyJSON library and dragged everything into my project navigation area. However when I go into the ViewController and add: import AlamofireSwiftyJSON I get the error: no such module import AlamofireSwiftyJSON...

how to sort JSON string alphabetically in swift?

ios,uitableview,sorting,swifty-json
I am using SwiftyJSON to parse the JSON from web, and then displaying those values in a tableView. I want to add a functionality to sort the data alphabetically ascending or descending according to the user names. I am new to Swift and having trouble sorting this. I would appreciate...

SwiftyJSON - no access to JSON data

swift,alamofire,swifty-json
I'm trying to parse server response produced by following code (api for rails app developed with grape) if user.persisted? return user.to_json else error!(user.errors.to_json, 400) end When user submit wrong data i see following response from server: { response = "{\"email\":[\"is invalid\"],\"password\":[\"is too short (minimum is 8 characters)\"]}"; "response_type" = error;...

How can I get JSON data when the value is a JSON value with swiftyJSON

ios,json,swifty-json
I'm using swiftyJSON in my iOS project but I have some trouble to get some data in my valid JSON... whoJson: [ { "name": "[{\"code\":\"en\",\"name\":\"John\"},{\"code\":\"fr\",\"name\":\"Jacques\"}]", "id": 1 }, { "name": "[{\"code\":\"en\",\"name\":\"Bob\"},{\"code\":\"fr\",\"name\":\"Robert\"}]", "id": 11 } ] With this code: println(who[0]["name"]) The result is: [{"code":"en","name":"John"},{"code":"fr","name":"Jacques"}] How can I get John or Jacques...

How to use swiftyjson to parse json data to foundation object and loop through data

swift,alamofire,swifty-json
So I'm trying to get his raw json data and use it to ultimately be viewed in a table(so one table cell would be --> Emirates - $1588.77) Problem: Having trouble parsing the JSON data.. alamofire apparently does it automatically? but im completely confused with the data types. I keep...

Parsing a json file returns unwanted result

ios,json,swift,swifty-json
After a bit of struggling I finally got my Json file to parse. Although I guess it is parsing.. I am getting nil when Trying to access a value with alot of "objects". This is my code using the swiftyJson library. And here is how my json looks like. The...

SwiftyJSON dictionary parsing

ios,json,swifty-json
I am attempting to use SwiftyJSON to parse some data from a server. For example, say the JSON returned from the server is: { "data":{ "id":"92", "name":"harry", "username":"Hazza" }, "error":false } I would like to get the username string and so to do this I obtain the data object using:...

iOS: Using HanekeSwift with SwiftyJSON

xcode,swift,ios8,swifty-json
I use Alamofire with SwiftyJSON in my current swift project. I would like to add HanekeSwift for caching. Adding HanekeSwift to the project make it "collide" with SwiftyJSON struct JSON. Is there any easy way to use both of these frameworks? I know there is a option to rename one...

SwiftyJSON Reading JSON Array issue

json,swift,swifty-json
I'm trying to read a json array data as below with my code but I'm getting empty result all the time while I can print the whole data. Please where would be my issue? I've read this topic but I couldn't get the result. Topic Link {"Cars":[{"Brand":"Alfa Romeo"},{"Brand":"Audi"},{"Brand":"BMW"},{"Brand":"Citroen"},{"Brand":"Dacia"},{"Brand":"Fiat"},.......... My code...

Creating TableViews in Swift with an Array

ios,swift,uitableview,swifty-json
I'm attempting to use the result of one Rest call as an input for my TableView. I've got an array named GamesList[String] that is synthesized in the viewDidLoad() function. This is the viewDidLoad() fuction: override func viewDidLoad() { super.viewDidLoad() getState() { (json, error) -> Void in if let er =...

How to handle ios data from API call

uitableview,swift,alamofire,swifty-json
When i call api using Alamofire like this Alamofire.request(.POST, "http://localhost:8080/xxx/xxx/xxx/xx").responseJSON() { (_, _, jsonData, error) in if error == nil{ var newItem=JSON(jsonData!) println(newItem) } else{ println("Nothing!") } } And I got many json format which include {"header","body"}. Header are like this "header" : { "toPage" : "3948", "totalCount" : "59212",...