0

I receive json as NSData, and want to serialise it but I can't get it going.

My code is the following:

func parseDownloadedData(inputData: NSData) -> (Bool)
{
    var error: NSError?
    var commonData: NSDictionary = NSJSONSerialization.JSONObjectWithData(inputData, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary

    if commonData.count > 0
    {
        var resultInArray : NSMutableArray = commonData.valueForKey("") as NSMutableArray

        for result in resultInArray
        {
            let origin = result.objectForKey("origin") as NSString!
            let friendlyNameLong = result.objectForKey("friendlyNameLong") as NSString!
            let state = result.objectForKey("state") as NSString!

            createEventObject(origin, friendlyNameLong: friendlyNameLong, state: state)
        }

        return true
    }
    else
    {
        return false
    }
}

I also tried creating the resultInArray with a key value, and then using commonData.valueForKey"that value"

But its not working.

My Json return is the following:

{
    "DeviceIpint.0/SourceEndpoint.video:0:0":
    {
        "origin": "DeviceIpint.0/SourceEndpoint.video:0:0"
        ,"state": "signal_restored"
        ,"friendlyNameLong": "0.Indkorsel"
        ,"friendlyNameShort": "IP уcтройcтво [0]"
    }
    ,"DeviceIpint.1/SourceEndpoint.video:0:0":
    {
        "origin": "DeviceIpint.1/SourceEndpoint.video:0:0"
        ,"state": "signal_lost"
        ,"friendlyNameLong": "1.Fasade"
        ,"friendlyNameShort": "IP уcтройcтво [1]"
    }
    ,"DeviceIpint.2/SourceEndpoint.video:0:0":
    {
        "origin": "DeviceIpint.2/SourceEndpoint.video:0:0"
        ,"state": "signal_restored"
        ,"friendlyNameLong": "2.Indgang"
        ,"friendlyNameShort": "IP уcтройcтво [2]"
    }
    ,"DeviceIpint.3/SourceEndpoint.video:0:0":
    {
        "origin": "DeviceIpint.3/SourceEndpoint.video:0:0"
        ,"state": "signal_restored"
        ,"friendlyNameLong": "3.Have"
        ,"friendlyNameShort": "IP уcтройcтво [3]"
    }
    ,"DeviceIpint.4/SourceEndpoint.video:0:0":
    {
        "origin": "DeviceIpint.4/SourceEndpoint.video:0:0"
        ,"state": "signal_restored"
        ,"friendlyNameLong": "4.Garage"
        ,"friendlyNameShort": "IP уcтройcтво [4]"
    }
}
0x416e746f6e
  • 9,542
  • 5
  • 37
  • 65
Clemen Gronver
  • 181
  • 3
  • 11

0 Answers0