简体   繁体   中英

printing dictionary of c# with javascript

Hi have some data to print in the client, the data is dictionary of <string,string> while userCountSpan.textContent = message; return to the screen `object object' and not the data in the dictonary. why?

JavaScript:

 document.addEventListener('DOMContentLoaded', function () {
        function bindConnectionMessage(connection) {
            var messageCallback = function (message) {
                console.log('message' + message);
                if (!message) return;
                var userCountSpan = document.getElementById('users');
                userCountSpan.textContent = message;
            };
            connection.on("updateCount", messageCallback);
            connection.onclose(onConnectionError);
        }

The value in message is the dictonary data 在此处输入图片说明

Excused me for I don't understand much what you asked. But is this what you want:

foreach(KeyValuePair<string, string> kvp in message)
{
      console.log("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM