简体   繁体   English

用javascript打印c#字典

[英]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;嗨有一些数据要在客户端打印,数据是<string,string>字典,而userCountSpan.textContent = message; return to the screen `object object' and not the data in the dictonary.返回屏幕“对象对象”而不是字典中的数据。 why?为什么?

JavaScript: 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 message 中的值是字典数据在此处输入图片说明

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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