DyKnow / SignalR-ObjC

Objective-C Client for the SignalR Project works with iOS and Mac
MIT License
442 stars 213 forks source link

SignalR ObjC wrapping response? #286

Closed arcade16 closed 7 years ago

arcade16 commented 7 years ago

I am working on an application that uses SignalR-ObjC. I have set up the connection to our server and am receiving the correct data, but the response object is throwing me off. I am trying to parse the response to JSON and then a dictionary, but it looks like SignalR-ObjC is wrapping the response in extra data that is preventing me from parsing it to JSON.

This is what a slice of my response looks like:

RESPONSE: {
    A =     (
        "{\"NotificationType\":1,\"TelemetryDetails\":{\"serialNumber\":\"xxx\",\"name\":\"xxx\",,\"protectedDeviceIp\":\"xxx\"},{\"endpoint\":\"xxx\",\"ip\":\"xxx\",\"domain\":null,\"latitude\":null,\"longitude\":null,\"protectedDeviceId\":\"xxx\",\"protectedDeviceIp\":\"xxx\"}]}]},\"CommandResult\":null,\"xxx\":\"xxx\"}"
    );
    H = NotificationsHub;
    M = notificationData;
}

On all other platforms, my response is only what the value for "A" is here. Not sure why SignalR-ObjC is wrapping the response with all this extra data (hub information).

This is how I parse the response:

 NSError *jsonError;
        NSData *objectData = [strData dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:objectData
                                                             options:NSJSONReadingMutableContainers
                                                               error:&jsonError];

If I copy and paste the value from "A" in my response object into where "strData" is being encoded, the code to parse it works fine. However if I pass the whole response object, it breaks.

Bearing in mind my response objects looks to be a string, how can I extract the value for "A" or stop SignalR-ObjC from wrapping my response with this extra data?