JSON: Extracting Data Using Alamofire and Swift 3

JSON: Extracting Data Using Alamofire and Swift 3

By : Neil
Date : November 21 2020, 03:00 PM
fixed the issue. Will look into that further Can anyone tell me how to get the data out of this JSON? , Figured it out.
code :
                    if let resData = result["items"].arrayObject {
                        arrRes = resData as! [[String:AnyObject]]
                        for element in arrRes[0]

Share : facebook icon twitter icon
Need your help, IOS Swift Post data to Json Alamofire

Need your help, IOS Swift Post data to Json Alamofire

By : user3223931
Date : March 29 2020, 07:55 AM
like below fixes the issue I got the answer, thanks to Karthikeyani for your help, I post the answer to share with everyone:
My PHP Script:
code :

/* include db.config.php */
// Get user id
$username = isset($_POST['username']) ? mysql_real_escape_string($_POST['username']) : “”;
$data = isset($_POST['signature']) ? mysql_real_escape_string($_POST['signature']) : “”;

// get user data
mysql_query('SET NAMES "utf8"');
$sql = mysql_query("UPDATE users SET signature = '$data' WHERE username='$username'");

/* JSON Response */

  @IBAction func Signature(sender: UIButton) {
        var signaturesave1 = self.signature.text
        let prefs:NSUserDefaults = NSUserDefaults.standardUserDefaults()
        var username = prefs.valueForKey("USERNAME") as NSString
        let parameters =
            ["username": username, "signature":signaturesave1]

        //load and parse the JSON into an array
        Alamofire.request(.POST, "http://mywebsite.com/app/data/jsonsavesignature.php", parameters: parameters).responseJSON { (request, response, data, error) in

                 self.performSegueWithIdentifier("signature_to_persoinfo", sender: self)

How can I put JSON data into a UILabel using AlamoFire and Swift

How can I put JSON data into a UILabel using AlamoFire and Swift

By : Nonbeliever
Date : March 29 2020, 07:55 AM
wish help you to fix your issue A few suggestions:
Yahoo offers https so use that You don't need to call dispatch_async before the Alamofire request. The request will be performed on a background thread by default. Since you are mapping a long list of fields, it's better to use a JSON-to-object mapping framework like ObjectMapper. You can have the fields in their native data types rather than strings. I can't help with the "thread 1 error" since I don't see your tableView:cellForRowAtIndexPath: method. So the rest of this answer is to focus on the JSON handling
code :
import Foundation
import ObjectMapper

struct Stock: Mappable {
    var symbol: String?
    var ask: Double?
    var lastTradeDate: NSDate?
    // other fields...

    var dataFields = [[String : String]]()

    init?(_ map: Map) {
        // Perform validation of the JSON here
        // Leave blank if you don't need to validate anything

    mutating func mapping(map: Map) {
        symbol          <- map["query.results.quote.symbol"] // maps to a String
        ask             <- map["query.results.quote.Ask"]    // maps to a Double

        // You probably want to combine this with LastTradeTime
        // but I'm keeing them as separate for now
        lastTradeDate   <- (map["query.results.quote.LastTradeDate"], MyDateTransform())

// We need a custom date formatter since Yahoo doesn't
// return the standard format of yyyy-MM-dd
class MyDateTransform : TransformType {
    typealias Object = NSDate
    typealias JSON = String

    static let dateFormatter = { Void -> NSDateFormatter in
        let formatter = NSDateFormatter()
        formatter.dateFormat = "M/d/yyyy"

        return formatter

    func transformFromJSON(value: AnyObject?) -> NSDate? {
        if let stringValue = value as? String {
            return MyDateTransform.dateFormatter.dateFromString(stringValue)
        } else {
            return nil

    func transformToJSON(value: NSDate?) -> String? {
        if let dateValue = value {
            return MyDateTransform.dateFormatter.stringFromDate(dateValue)
        } else {
            return nil
let stockURL = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22AAPL%22)&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&format=json"

Alamofire.request(.POST, stockURL)
    .responseJSON { response in
        guard response.result.isSuccess else {

        // This is all it takes to initiate a new object from JSON
        let stock = Mapper<Stock>().map(response.result.value)
Parsing JSON data with Gloss and Alamofire in swift

Parsing JSON data with Gloss and Alamofire in swift

By : Anass Boulmane
Date : March 29 2020, 07:55 AM
it fixes the issue Ok, problem solved. It was a faulty configuration of the webservice. As you can see, the json response of the code attribute was:
code :
 "code": "0", 
"code": 0, 
guard let codeStr : String = "code" <~~ json else {
    print("code unwrapping failed in guard")
    return nil
self.code = Int(codeStr)!
How to pass data in JSON Encoding with Alamofire Swift 4

How to pass data in JSON Encoding with Alamofire Swift 4

By : Peeyushlko
Date : March 29 2020, 07:55 AM
To fix this issue Can't figure out how to pass date to the server with Alamofire .post method. I have to form JSON body like this: , You can try
code :
let parameters: Parameters = [
    "title": Event.title ?? nil,
    "locations": [["location":"idherrr"]]
Parse JSON data with Swift, AlamoFire and SwiftyJSON

Parse JSON data with Swift, AlamoFire and SwiftyJSON

By : Tros Alba
Date : March 29 2020, 07:55 AM
help you fix your problem As a Swift newcomer, I am very confused about how to parse some JSON data obtained from an API. I am able to get the JSON data from the api using an alamofire request. At this point, I think I have an NSDictionary object, JSON as print(JSON) logs to console a good deal of JSON. , Can you try
code :
if let result = response.result.value as? [String:Any] {
   if let contact = result["contact"] as? [String:Any] {
      if let first = contact["first"] as?  String {
let data = JSON(data: JSON)
Related Posts Related Posts :
  • Artefact in shader for iOS
  • Make async request in table view delegate method
  • (iOS) Escaping single quote in XML
  • Change the UIButton Image when tapped multiple times
  • Convert string JSON response to a boolean using Swift 4 Decodable
  • [iOS]renew push certificate but don't have certificateSigningRequest file
  • How to change src value in UIWebView?
  • Inserting into Array and comparing Dates Swift iOS Code
  • IBDesignable UI is not showing in Xcode 9 with Swift
  • Ask for only Request Always Authorization, and not When-In-Use Authorization
  • "Google/Analytics.h file not found" after updating pod to GoogleAnalytics
  • Post request with HTTP header parameters
  • Managing cookies for a domain in Associated Domains
  • Array items showing error in IOS
  • Saving asynchronously downloaded files' contents to SQLITE
  • Swift 4 - animating both alpha and constraint affects other components alpha value
  • UIView animation in completion block starts with displacement
  • List all Apps and Track Internet Usage
  • Handling Back To Back HTTP Posts SWIFT 4.0
  • Azure App Service Push - registration endpoint
  • Select multiple item in a tableView
  • Apartment number / Unit number returned from google places api
  • How to align UICollectionViewCells from left to right?
  • How can I add search option on UIPickerview in ios?
  • Scenekit - physicsWorld setup to prevent kinematic nodes to intersect
  • Carthage Build Failed
  • swift 3, ios 10 - push notification firebase is not received
  • App Xcode 8 to Xcode 9 - Prevent Auto Hide Status Bar
  • How to pop back to a TableViewController?
  • Is UserDefaults thread safe in Swift? How to check it?
  • UISwitch in a table selects multiple cells when switch state on
  • iOS App with no story board (Size classes and Device type limitations)
  • AudioKit issue, mic not sensitive enough
  • send indexpath to Firebase (like button)
  • UIColor saturation brightness values different from the regular saturation luminosity values of a color
  • invalid_grant on OAuth2 request when obtaining access_token from SSO in App
  • ABNewPersonViewController using contact framework
  • Design iOS button scalable
  • Subclassing NSLayoutConstraint constant based on screen height
  • Migrate Realm 2.x List of Object to Realm 3.x List of String (or other primary type)
  • Using BLE RSSI value for connect-by-proximity
  • Backgroundcolor of NSTextfield
  • Firebase modifying uid in every view
  • How to rotate orientation?
  • Upload a new version of ios app to app store?
  • UIScrollView do not scroll down to its original position when keyboard disappear
  • What is the most effective way of tracking time/dates in an iOS/Swift application?
  • WatchKit get user's preferred handedness
  • Location permission dialog is shown and immediately disappears
  • Combine these regex expressions
  • How to save an array of HKQuantitySamples (heart rate) to a workout
  • RestKit mapping with parent key as attribute and key contains parenthesis
  • How to add UITextField programmatically to UIScrollView without breaking constraints?
  • How to make a view height grow depending on its child views contents
  • Some users experiencing NSInternalInconsistencyException crash
  • Mark successful siesta response as error
  • Using a modified PDFTron Tools Framework
  • How can I use universal links when I call openURL inside my own app?
  • NSArray of doubles iOS (Objective c)
  • Passing data from embedded PageViewController to parent View Controller
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org