arrays – How to parse a string from JSON to UILabel using AFnetworking?

Question:

I have a method in which I receive an array and take the elements I need

open class OBCSDKCourierTracking: NSObject {

var dataInfo: [OBCSDKCourierAWBs] = []
var getAWB: [OBCSDKGetCourierAWB] = []

class func getCourierAWBs(completion: @escaping ([OBCSDKCourierAWBs], OBCSDKError?) -> Void){

    let body = ["data_list"]

    HTTPManager.post("External_Obc.getCourierAWBs", body: body, success: { (response: Any?) -> Void in
        print("[Response] - OBCSDKCourierTracking/Get Courier AWBs: \(response)")

        var arrays: [OBCSDKCourierAWBs] = []
        let error = OBCSDKError(response: response)

        // Failure
        if !error.status {
            completion([], error)
        } else {

            if let info = response as? [String : AnyObject] {
                if let list = info["data_list"] as? NSArray {

                    list.enumerateObjects({ (obj: Any?, index: Int, stop) in
                        let dataListInfo = obj as! NSDictionary

                        let dataList = OBCSDKCourierAWBs()

                        dataList.awbNo = dataListInfo["awb_id"] as? String
                        dataList.cargoDescription = dataListInfo["cargo_descr"] as? String
                        dataList.originIcao = dataListInfo["origin_icao"] as? String
                        dataList.originIata = dataListInfo["origin_iata"] as? String
                        dataList.pcs = dataListInfo["pcs"] as? String
                        dataList.status = dataListInfo["status"] as? String
                        dataList.weightCh = dataListInfo["ch_weight"] as? String
                        dataList.weightGross = dataListInfo["gross_weight"] as? String
                        dataList.desIata = dataListInfo["dest_iata"] as? String
                        dataList.desIcao = dataListInfo["dest_icao"] as? String

                        arrays.append(dataList)
                    })
                }
            }
        }

        completion(arrays, nil)

    }, failure: { (error: Error) -> Void in
        print("[Failure] - OBCSDKCourierTracking/Get Courier AWBs: \(error.localizedDescription)")
        // Completion handler
        completion([], error.convert)
    })
}

I also have a class with these objects

import UIKit



class OBCSDKCourierAWBs: NSObject {

    //awb_no
    open var awbNo: String?
    //status
    open var status: String?
    open var pcs: String?
    //
    open var originIcao: String?
    open var originIata: String?
    //
    open var weightCh: String?
    open var weightGross: String?
    //
    open var cargoDescription: String?
    //
    open var desIata: String?
    open var desIcao: String?

}

In my UIViewController in the viewDidLoad () function it looks like this

internal var arrayElement =  [OBCSDKCourierAWBs]()

override func viewDidLoad() {
    super.viewDidLoad()

    OBCSDKCourierTracking.getCourierAWBs(completion: { (arrays: [OBCSDKCourierAWBs], error: OBCSDKError?) in

        self.arrayElement = arrays


    })

My question is how in the controller, after the array of elements [OBCSDKCourierAWBs] come to my method, to extract the "awb_id" element from it and pass it to the UILabel ?

self.myLable?.text = 

Answer:

It depends on which element in the array, for example, the first

self.myLabel?.text = self.arrayElement.first.awbNo

if I understood the question correctly

Scroll to Top