0

I'm trying to get the response from API, but some of the values are missing, how I can get the values, My response is this,

{
"responseHeader": {
    "code": 1,
    "msg": "Data Retrived Successfully "
},
"responseBody": {
    "data": [
        {
            "totalPages": 1,
            "pageNumber": 0,
            "numberOfElements": 3,
            "totalRecords": 3,
            "data": [
                {
                    "buyerProcessId": 55,
                    "bidReferenceNo": "BidReferenceNo-439187-GEA",
                    "biddingStatus": null,
                    "chiraghuser": {
                        "userId": 1678,
                        "userName": "mutiurrehman111",
                        "userEmail": "[email protected]",
                        "firstName": "Muti",
                        "middleName": null,
                        "lastName": "urRehman",
                        "mobileNo": "3477002202",
                        "streetAddress": null,
                        "buildingAddress": "Dubai Tower - D89 - Dubai - United Arab Emirates",
                        "emailVerificationCode": null,
                        "mobileOtpCode": "8712",
                        "cityId": 1,
                        "otpCodeExpiration": null,
                        "profilePicUpload": null,
                        "token": "1",
                        "role": "chiraghuser",
                        "nationality": "Pakistani",
                        "idCardNumber": null,
                        "idCardExpiryDate": null,
                        "passportNumber": null,
                        "passportExpiryDate": null,
                        "phoneNumber": null,
                        "fax": null,
                        "classifyYourself": null,
                        "country": null,
                        "userCity": null,
                        "scannedPassportCopyUpload": null,
                        "scannedIdCopyUpload": null,
                        "oldPasssword": null,
                        "status": "activated",
                        "nationalityOther": null,
                        "securityOtp": "4491",
                        "mobileCode": "92",
                        "telephoneCode": null,
                        "countryId": 162,
                        "isApproved": null
                    },
                    "chiraghproperty": {
                        "propertyId": 36567,
                        "propertyTitle": "Jumeirah Village Triangle , 4 Beds, Town House",
                        "propertyDescription": "Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - ",
                        "location": null,
                        "sizePerSqft": 0.0,
                        "address": "Dubai - United Arab Emirates",
                        "askingPrice": 0.0,
                        "areaPermitNo": null,
                        "propertyReferenceNo": "Prop-840146-BFU",
                        "pricePerSqft": 0.0,
                        "isMdApproved": true,
                        "isPublished": null,
                        "noOfBedrooms": 4,
                        "noOfBaths": 3,
                        "floorNo": null,
                        "kitchens": null,
                        "carParks": null,
                        "noOfFloors": null,
                        "propertyTypeId": null,
                        "scannedTitleDeed": null,
                        "mapLocation": "25.0472882,55.190022699999986",
                        "plotNo": null,
                        "titleDeedNo": null,
                        "typeArea": "Non-Free Hold",
                        "projectName": "Jumeirah Village Triangle ",
                        "ownerAssociationNo": null,
                        "presentUse": "Residential",
                        "communityNo": null,
                        "propertyAge": null,
                        "noUnits": null,
                        "noShops": null,
                        "userId": null,
                        "leaseStartDate": null,
                        "leaseExpiryDate": null,
                        "tenantName": null,
                        "tenancyContractUpload": null,
                        "thirdPartyVerification": "true",
                        "isThirdPartyPayment": null,
                        "verificationHodApproved": "1",
                        "valuationHodApproved": false,
                        "isVacant": null,
                        "agreeVatCommission": false,
                        "amount": 0.0,
                        "balanceAmount": 0.0,
                        "propertyNo": null,
                        "propertyStatus": "Off-Plan",
                        "propertyType": "Town House",
                        "area": null,
                        "lastActionPerformed": "Not Started",
                        "isPersonalDetailsVerified": null,
                        "isPoaDetailsVerified": null,
                        "isPropertyDetailsVerified": "true",
                        "isAcknowledgementCall": null,
                        "dateReceived": "2019-10-21",
                        "lastAction": null,
                        "actionPerformedBy": null,
                        "sellerUserName": "Test_User",
                        "status": "active",
                        "areaUnit": "sqft",
                        "isPropertyFinancialDetailsVerified": null,
                        "isPropertyRentalDetailsVerified": null,
                        "bankOther": null,
                        "netArea": "980",
                        "grossArea": "1500",
                        "floorPlanUpload": null,
                        "typePropertyOther": null,
                        "propertyStatusOther": null,
                        "bulidingName": null,
                        "bulidingNumber": null,
                        "isVerificationHodApproved": "false",
                        "valuationAssignTo": null,
                        "brokerageAssignTo": null,
                        "isValuationCompleted": null,
                        "valuationReportCopy": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665049034-1valuation.pdf",
                        "isThirdPartyValuationCompleted": null,
                        "thirdPartyReportCopy": null,
                        "isValuationReportUploaded": "true",
                        "valuationReportDocument": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665045520-1valuation.pdf",
                        "isValuationHodApproved": "1",
                        "isBrokerageCompleted": null,
                        "isBrokerageReportUploaded": "true",
                        "brokerageReportCopy": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665219758-1valuation.pdf",
                        "isBrokerageHodApproved": "1",
                        "price": null,
                        "isWatchedList": null,
                        "auctionStatus": "live",
                        "developerName": "dev",
                        "makaniNo": null,
                        "adminPropertyStatus": "new",
                        "requestedChanges": null,
                        "priceUnit": null,
                        "telephoneCode": null,
                        "mobileCode": null,
                        "listingChecklistConfirm": true,
                        "listingHodApproved": "1",
                        "verificationChecklistConfirm": null,
                        "valuationChecklistConfirm": null,
                        "brokerageChecklistConfirm": null,
                        "financeChecklistConfirm": null,
                        "isFinanceHodApproved": null,
                        "verificationAssignTo": null,
                        "otherDocument": null,
                        "spaDocument": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571664075956-1valuation.pdf",
                        "okoodiNo": "787878787",
                        "netAreaUnit": "sqft",
                        "officeNo": null,
                        "departementId": null,
                        "userRoleId": null,
                        "isOwnerVerified": false,
                        "isPoaVerified": false,
                        "isPropertyVerified": false,
                        "isReportVisibleToSeller": null,
                        "formAUpload": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665216574-1valuation.pdf",
                        "isFormAUploaded": 1,
                        "isValuationReportCopyUploaded": null,
                        "isRegistrationReady": null,
                        "rentalOtherDocument": null,
                        "thirdpartyHodApproved": null,
                        "listingTitle": "Jumeirah Village Triangle , 4 Beds, Town House",
                        "listingDescription": "<p>Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle - Jumeirah Village Triangle -</p>",
                        "buyerProcessId": 0,
                        "images": [
                            {
                                "propertyId": 36567,
                                "imageUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665096963-95a23be9d1e876b1ae03514493ff69cc_mod_1.jpg",
                                "imageName": "ordinary",
                                "fileName": null,
                                "isVisible": null,
                                "thumbnailUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665097160-95a23be9d1e876b1ae03514493ff69cc_mod_1.jpg"
                            },
                            {
                                "propertyId": 36567,
                                "imageUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665099672-49836-1.jpg",
                                "imageName": "ordinary",
                                "fileName": null,
                                "isVisible": null,
                                "thumbnailUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665099909-49836-1.jpg"
                            },
                            {
                                "propertyId": 36567,
                                "imageUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665102680-292968_16012118210039308812.jpg",
                                "imageName": "ordinary",
                                "fileName": null,
                                "isVisible": true,
                                "thumbnailUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665102759-292968_16012118210039308812.jpg"
                            },
                            {
                                "propertyId": 36567,
                                "imageUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665106366-1804.png",
                                "imageName": "ordinary",
                                "fileName": null,
                                "isVisible": true,
                                "thumbnailUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665106475-1804.png"
                            },
                            {
                                "propertyId": 36567,
                                "imageUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665112768-37605408-800x600.jpeg",
                                "imageName": "ordinary",
                                "fileName": null,
                                "isVisible": null,
                                "thumbnailUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665112906-37605408-800x600.jpeg"
                            },
                            {
                                "propertyId": 36567,
                                "imageUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665117617-130257047.jpg",
                                "imageName": "main-ordinary",
                                "fileName": null,
                                "isVisible": true,
                                "thumbnailUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665117694-130257047.jpg"
                            },
                            {
                                "propertyId": 36567,
                                "imageUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665122815-117127050.jpg",
                                "imageName": "ordinary",
                                "fileName": null,
                                "isVisible": null,
                                "thumbnailUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571665122878-117127050.jpg"
                            },
                            {
                                "propertyId": 36567,
                                "imageUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571676983964-10-marla-house-design-luxury-new-indian-exterior-house-designs-s-of-10-marla-house-design.jpg",
                                "imageName": "ordinary",
                                "fileName": null,
                                "isVisible": true,
                                "thumbnailUrl": "https://s3.us-east-2.amazonaws.com/chiragh-asset/1571676984241-10-marla-house-design-luxury-new-indian-exterior-house-designs-s-of-10-marla-house-design.jpg"
                            }
                        ],
                        "propertyBids": null,
                        "country": {
                            "countryId": 0,
                            "name": null,
                            "isActive": null,
                            "nationality": null,
                            "iso2": null,
                            "iso3": null,
                            "code": null,
                            "cities": []
                        },
                        "city": {
                            "cityId": 0,
                            "name": null,
                            "isActive": null
                        }
                    },
                    "processType": "open_house",
                    "paymentStatus": null,
                    "openHouseNotes": null
                }
]
}]}

This is my model class through which i'm passing json in my model class,

    import ObjectMapper

class OpenHouseModel: Mappable {

    var totalPages : Int?
    var pageNumber : Int?
    var numberOfElements : Int?
    var totalRecords : Int?
    var propertyData : [PropertyData]?

    required init?(map: Map) {

    }

    func mapping(map: Map) {

        totalPages <- map["totalPages"]
        pageNumber <- map["pageNumber"]
        numberOfElements <- map["numberOfElements"]
        totalRecords <- map["totalRecords"]
        propertyData <- map["data"]
    }
}

class PropertyData: Mappable {

    var buyerProcessId : Int?
    var bidReferenceNo : String?
    var processType : String?
    var chiraghProperty : ChiraghProperty?
    var images : [PropertyImages]?

    required init?(map: Map) {

    }

    func mapping(map: Map) {

        processType <- map["processType"]
        buyerProcessId <- map["buyerProcessId"]
        buyerProcessId <- map["bidReferenceNo"]
        chiraghProperty <- map["chiraghproperty"]
        images <- map["images"]
    }
}


class ChiraghProperty: Mappable {

    var propertyId : Int?
    var propertyTitle : String?
    var propertyDescription : String?
    var sizePerSqft : Double?
    var address : String?
    var propertyReferenceNo : String?
    var pricePerSqft : Double?
    var noOfBedrooms : Int?
    var noOfBaths : Int?
    var typeArea : String?
    var projectName : String?
    var presentUse : String?
    var propertyType : String?
    var dateReceived : String?
    var areaUnit : String?
    var status : String?
    var netArea : String?
    var grossArea : String?
    var valuationReportCopy : String?
    var valuationReportDocument: String?
    var brokerageReportCopy: String?
    var spaDocument : String?
    var formAUpload : String?

    required init?(map: Map) {

    }

    func mapping(map: Map) {

        propertyId <- map["propertyId"]
        propertyTitle <- map["propertyTitle"]
        propertyDescription <- map["propertyDescription"]
        sizePerSqft <- map["sizePerSqft"]
        address <- map["address"]
        propertyReferenceNo <- map["propertyReferenceNo"]
        pricePerSqft <- map["pricePerSqft"]
        noOfBedrooms <- map["noOfBedrooms"]
        noOfBaths <- map["noOfBaths"]
        typeArea <- map["typeArea"]
        projectName <- map["projectName"]
        propertyType <- map["propertyType"]
        dateReceived <- map["dateReceived"]
        areaUnit <- map["areaUnit"]
        status <- map["status"]
        netArea <- map["netArea"]
        valuationReportCopy <- map["valuationReportCopy"]
        valuationReportDocument <- map["valuationReportDocument"]
        brokerageReportCopy <- map["brokerageReportCopy"]
        spaDocument <- map["spaDocument"]
        formAUpload <- map["formAUpload"]

    }
}


class PropertyImages: Mappable {

    var imageUrl : String?
    var imageName : String?

    required init?(map: Map) {

    }

    func mapping(map: Map) {

        imageUrl <- map["imageUrl"]
        imageName <- map["imageName"]
    }
}

Now when I run the code and get values I get nil for buyerProcessId key. Other values are coming fine, I don't know why it isn't showing values for these keys above chiraghuser.

5
  • Why aren't you using Codable instead? Commented Oct 24, 2019 at 10:33
  • i know your stance, but yet i have to use that. @PGDev Commented Oct 24, 2019 at 10:47
  • @PGDev Why shouldn't Hamza use objectmapper? Commented Oct 24, 2019 at 10:54
  • Can u please help in getting values above chiraghuser object? @JeremyP Commented Oct 24, 2019 at 11:05
  • @Hamza I didn't know the answer. Commented Oct 25, 2019 at 7:11

2 Answers 2

1

It looks like your issue is in PropertyData as you appear to be mapping the bidReferenceNo to buyerProcessId. That is why your are getting nil.

class PropertyData: Mappable {

    var buyerProcessId : Int?
    var bidReferenceNo : String?
    var processType : String?
    var chiraghProperty : ChiraghProperty?
    var images : [PropertyImages]?

    required init?(map: Map) {

    }

    func mapping(map: Map) {

        processType <- map["processType"]
        buyerProcessId <- map["buyerProcessId"]
        buyerProcessId <- map["bidReferenceNo"] // this seems like it is wrong and should be bidReferenceNo
        chiraghProperty <- map["chiraghproperty"]
        images <- map["images"]
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

OMG thank alot i have made blunder. thanks for identifying this. @Andrew
1

Since you are using ObjectMapper, you can reduce a lot of boilerplate code by using BetterMappable which is written over ObjectMapper using PropertyWrappers. You need to be on Swift 5.1 to use it.

Once you use BetterMappable in your codebase, your model will look like this.

class PropertyData: Mappable {

    @JSONProperty var buyerProcessId : Int?
    @JSONProperty var bidReferenceNo : String?
    @JSONProperty var processType : String?
    @JSONObject var chiraghProperty : ChiraghProperty?
    @JSONObjectArray var images : [PropertyImages]?

    required init?(map: Map) {

    }
}

1 Comment

Thanks @Srikanth. I was looking for something like this for a very long time 87👏

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.