swifty-json

saving swifty json array to user defaults

 ̄綄美尐妖づ 提交于 2021-02-16 16:36:23
问题 i have a json data which gives the following information: let data = [ { "QuestionTitle" : "Entomology is the science that studies", "Id" : 205, "Options" : [ { "Option" : "Insects", "Id" : 810 }, { "Option" : "The origin and history of technical and scientific terms", "Id" : 811 }, { "Option" : "The formation of rocks", "Id" : 812 }, { "Option" : "Behavior of human beings", "Id" : 809 } ] }, { "QuestionTitle" : "A train running at the speed of 60 km\/hr crosses a pole in 9 seconds. What is

How to combine two SwiftyJSON objects

隐身守侯 提交于 2021-02-07 06:54:27
问题 I have a swiftyJSON object that looks like for example: [{ "location" : "http://...", "img" : "http://...", "commentCount" : 0, "timestamp" : 1432460217550, }] I want to be able to append another swiftyJSON object to it so that it looks like: [{ "location" : "http://...", "img" : "http://...", "commentCount" : 0, "timestamp" : 1432460217550, }, { "location" : "http://...", "img" : "http://...", "commentCount" : 1, "timestamp" : 1432460217571, } ] I can't use += or .append on swiftyJSON

post json request in swift

本小妞迷上赌 提交于 2020-06-26 14:00:34
问题 I know how to post simple json: // Compose a query string let postString = “firstName=James&lastName=Bond”; request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding); Now the server side require the json format like: { "name": "testuser123", "pass": "testuser123", "field_shouji": { "und": [{ "value": "15652344931" }] } } and the content type should be: application/json. I have googled the whole day, still could find the right way. 回答1: You need to send a valid format of JSON.

Swift safely unwrapping optinal strings and ints

。_饼干妹妹 提交于 2020-06-24 12:17:12
问题 When I am about to fire my segue for the 2nd view I also send some values like this: if let aTime = ads[indexPath.row]["unix_t"].int { toView.time = aTime } if let aTitle = ads[indexPath.row]["title"].string { toView.title = aTitle } In the second VC I have declared the varibles like: var time: Int? var title: String? and this is how I unwrap the values: if time != nil { timeLabel.text = String(time!) } if title != nil { titleLabel.text = title! } This all works I never get any error caused

My Swift framework not working in ObjectiveC but works fine in Swift

我们两清 提交于 2020-01-16 18:08:07
问题 I have created a Swift framework that creating a button programmatically, and the action of the button is showing a webView and close it, my framework works fine in Swift project but in Objective C it just create button but it is not taking action and does not show my webView, Note: I am getting the button configuration from server via JSON using SwiftyJSON below is the my Swift Class in addition to SwiftyJSON in the framework project import Foundation import UIKit import WebKit @objc public

Swift: How to install SwiftyJson using cocoapods?

家住魔仙堡 提交于 2020-01-07 08:57:12
问题 I'm trying to install cocoapods here: https://github.com/SwiftyJSON/SwiftyJSON but when I import SwiftyJSON in my view file, it says No such module 'SwiftyJSON' My Podfile: platform :ios, '8.0' inhibit_all_warnings! use_frameworks! target 'SherpaNewYork' do pod 'GoogleMaps' pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git' end After adding that I ran pod install succesfully: [~/Documents/ios/Sherpa]$ pod install ✭ git:master ruby:2.2.2 Updating local specs repositories

Results won't append from JSON

自作多情 提交于 2020-01-03 06:18:05
问题 The JSON file I am using: https://api.myjson.com/bins/49jw2 I am using SwiftyJSON for parsing. The variable chores wont be populated outside the method parseJson var chores: [String] = [] override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. tfWhat.delegate = self tfHowMuch.delegate = self loadJson() // wont even print for chore in self.chores { print("beschrijving: " + chore) } // prints 0 print(chores.count) } func loadJson() -> Void { let url

How to get data from JSON response in iOS Swift?

六眼飞鱼酱① 提交于 2019-12-25 18:54:43
问题 Here i have using swiftyJson pod library for response data. normal json response data i could able to get data but for complex i could not make it. here is my code to get data from response: private func makeHTTPGetRequest(path: String, onCompletion: @escaping ServiceResponse) { let user = "David****" let password = "**************" let loginString = "\(user):\(password)" guard let loginData = loginString.data(using: String.Encoding.utf8) else { return } let base64LoginString = loginData

How to save JSON data from a POST Request into dictionary with Swifty Json?

≯℡__Kan透↙ 提交于 2019-12-25 04:45:12
问题 I was able to print the json data in console which looks like this { "created_at" : "2016-07-21 20:46:53", "name" : "PB Admin", "id" : 1, "updated_at" : "2016-07-21 12:46:53", "lname" : "Admin", "access_lvl" : 1, "email" : "admin@admin.com", "fname" : "PB" } , but could not save it into a dictionary. The method for POST request private func makeHTTPPostRequest(path: String, body: NSDictionary) { let request = NSMutableURLRequest(URL: NSURL(string: path)!) // Set the method to POST request

Alamofire, Swift 2.0, SwiftyJSON: Parse response body as JSON

早过忘川 提交于 2019-12-25 03:35:36
问题 I have successfully completed a POST request to server and I am trying to parse the response JSON but I have been unsuccessful. Alamofire.request(.POST, ServerConfig.ADD_SELLER_URL, parameters: sellerJSON, encoding: .JSON, headers: nil) .responseJSON(completionHandler: { responseRequest, responseResponse, responseResult in print(responseRequest!.URL) print(responseResponse) print(responseResult) let json = JSON(responseResponse!) print(json) }) I am using SwiftyJSON for JSON parsing. Here is