我有AnyObject车辆。需要访问车辆对象的值

时间:2015-07-22 08:39:00

标签: swift uitableview uilabel viewcontroller

{
        "id": 144241,
        "name": "Teltonika Test 8",
        "vrn": "ML57CEU3",
        "make": "Ford",
        "model": "Focus",
        "year": null,
        "icon": "red_car",
        "fuelType": "Petrol",
        "odometer": null,
        "useCostMile": 77,
        "idleCostHour": 77,
        "taxDate": "2015-12-05",
        "motDate": "2015-12-05",
        "nextServiceDate": "2015-12-05",
        "createdAt": 1433237926000,
        "updatedAt": 1433237926000,
        "privateCostPerMile": 77,
        "idleAlertTime": 77,
        "repeatPtoAlertTime": null,
        "payload": 0,
        "notifyMileage": 77,
        "siteVehicleType": null,
        "realRoadSpeed": false,
        "customer": {
            "id": 13492
        },
        "depot": {
            "id": 13492
        },
        "vehicleType": null,
        "deviceConfiguration": {
            "id": 139973
        },
        "liveView": {
            "id": 144061,
            "gpsPosition": {
                "id": 9209187941,
                "latitude": 3216.882,
                "longitude": -9.45553,
                "speed": 25,
                "heading": 0,
                "dateTime": 1351400858000
            },
            "currentStatus": "moving",
            "creationTime": 1433237926000,
            "createdAt": 1433237926000,
            "updatedAt": 1433237926000,
            "clockMeters": 77,
            "lastState": null,
            "batteryPercent": null
        },
        "businessHours": [
            {
                "id": 189251
            }
        ],
        "driver": null,
        "imei": null
    },

我想在liveview中显示lastState。我没有在Swift编程中包装概念。

1 个答案:

答案 0 :(得分:0)

试一试。

var dict = vehicleObject as! [String: AnyObject]
var liveViewDict = dict["liveView"]! as! [String : AnyObject]
var lastState = liveViewDict["lastState"] as! String

此外,由于此值为null而非nil,因此您需要检查NSNull的值。