【发布时间】:2014-10-22 17:39:59
【问题描述】:
这就是我的 c# 代码中的内容
using Newtonsoft.Json;
.....
Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("id", id.ToString());
d.Add("type", "error");
d.Add("msg", pex.Message);
.....
return JsonConvert.SerializeObject(d);
我的 AJAX
......
$.ajax({
type: "POST",
url: "Service1.svc/MyCall",
data: JSON.stringify(parameters),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
beforeSend: function () {
$("#lblResult").html("loading");
},
success: function (data) {
$("#lblResult").html(data['id']);
},
......
这是 Firebug 中的响应
"{\"id\":\"1\",\"type\":\"error\",\"msg\":\"An exception occurred during a Ping request.\"}"
这是 Firebug 中的 JSON
0 "{"
1 """
2 "i"
3 "d"
4 """
5 ":"
6 """
7 "1"
8 """
9 ","
10 """
11 "t"
ETC
问题:我无法获取数据['id'] 或任何数据['SOMETHING']。
如何根据收到的回复获取它? 还有其他方法吗?
【问题讨论】:
-
已经尝试过了,但我在 $("#lblResult").html(data['id']); - 没有细节或什么都没有
标签: c# jquery ajax json dictionary