Pergunta

Trying to get SignalR JSON object (complex object) over to client. The client is receving it and when looking at the network analyzer in IE, the format looks correct and the data is there, but I am unable to actually get at the data in the client. I tried using the JQuery JSON parsng and now I'm trying to get JSON.parse to work.

Here is my code in the client:

// Build connection to hub and wire it up
        var subscriber = $.connection.subscriberHub;


        subscriber.getMessage = function (data) {

            alert("Message Recieved: " + data);
            var parsedObject = JSON.parse(data);
            alert("Object parsed");
            alert(parsedObject.Site);
            alert("Passed everything without error");
        };

        $.connection.hub.url = "http://localhost:8083/signalr";
        $.connection.hub.start();


    });

Server I am just doing a Clients.getMessage(signalRObject).

When I get data, the first alert shows data as [object Object], so I think I am good up to the point of parsing the JSON object.

Can someone tell me the proper way to get at the data.

Foi útil?

Solução

i think you are doing well, but make sure that Json data properties on the server are used with the same names in the client side, i mean if you return json as:

{Msg : 'Hello', SiteUrl: 'www.mysite.com'}

then on the client side after you serialize the json object then you can write:

alert(parsedObject.SiteUrl);

Outras dicas

Forget this question.. turns out that SignalR is passing it asa true JSON object and it is easily used by doing data.Property1

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top