任何人都可以阐明为什么我的 JSON 会出现在下面,并带有额外的反斜杠。我正在使用 ASP.net MVC 序列化数据表,当我在 Visual Studio 中调试时它看起来一切正常但是当我使用 firebug 时添加了额外的字符?
有什么想法吗?
JSON
[{\"uid\":\"516219026\",\"pic\":\"http://profile.ak.net/\",\"first_name\":\"Daniel\",\"last_name\":\"James\",\"fql_query_response_Id\":0,\"LIFEID\":null}
JavaScript
function GetFBFriends() {
FB.Connect.requireSession(function() {
$.ajax({
url: "/Facebook/GetFaceBookFriends",
type: 'POST',
data: null,
dataType: 'json',
success: function(result) {
data = "<table>";
alert(result.length);
for (i = 0; i < result.length; i++) {
data += "<tr><td><td><img src=" + result[i].pic + " alt=" + result[i].first_name + " /></td><input type='checkbox' value='" + result[i].uid + "' name='friends[]' id = 'friend" + result[i].uid + "' /></td><td>" + result[i].first_name + " " + result[i].last_name + "</td></tr>";
}
data += "</table>";;
}
});
})
};
Public Function GetFaceBookFriends() As JsonResult
Dim fbFriends As New DataTable
Try
fbFriends = FacebookModel.GetFriendsAndMatchToLife()
Return Json(JsonConvert.SerializeObject(fbFriends))
Catch ex As Exception
Finally
fbFriends.Dispose()
fbFriends = Nothing
End Try
End Function
最佳答案
那是 Firebug,它在字符串表示中显示了包含 JSON 的字符串。将其视为对包含 JSON 的字符串进行 JSON 编码。或者更确切地说,如果您将 JSON 放入 Javascript 中的字符串文字中,它看起来会像这样。
您的字符串实际上不包含那些反斜杠。它们只是双引号的转义符。
关于javascript - JSON 和反斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2179973/