相关疑难解决方法(0)

在Javascript中阅读C#字典

我在C#(ASP.NET)中有一个字典变量.我想将此数据发送到Javascript.我正在使用此代码序列化它并发送到javascript.

Dictionary<string, string> chat;
chat = new Dictionary<string, string>();

chat.Add("Sam", "How are you?");
chat.Add("Rita", "I am good");
var serialize = new System.Web.Script.Serialization.JavaScriptSerializer();

Response.Write(serialize.Serialize(chat));
Run Code Online (Sandbox Code Playgroud)

在Javascript页面上,我使用此调用此页面;

 $.ajax({
 url: "TextChatCalls/getChat.aspx",
 type: "POST",
 context: document.body,
 success: function (response) {
          var Chats = response.split('\n')[0];
          alert(Chats);

          }
 });
Run Code Online (Sandbox Code Playgroud)

Chats var中的值是 {"Sam":"How are you?","Rita":"I am good"}

我不知道怎么在Chats中读取这个值.我可以无论如何将其转换为2D数组并将其读取为数组[0] [0],数组[1] [0]等?

谢谢.

编辑:另一个困惑是,从ASP.NET返回的响应对象包含

{"Sam":"How are you?","Rita":"I am good"}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>

</title></head>
<body>
    <form name="form1" method="post" action="getChat.aspx?Id=141755" id="form1">
<div>
<input type="hidden" …
Run Code Online (Sandbox Code Playgroud)

javascript asp.net jquery json dictionary

13
推荐指数
1
解决办法
3万
查看次数

标签 统计

asp.net ×1

dictionary ×1

javascript ×1

jquery ×1

json ×1