JSON and backslash

Can anyone shed some light on why my JSON goes below with extra backslashes. I use ASP.net MVC to serialize a datatable, when I debug Visual Studio, everything looks fine, but when I look with firebug with extra characters added?

Any ideas anybody?

"[{\"uid\":\"516219026\",\"pic\":\"http://profile.ak.net/\",\"first_name\":\"Daniel\",\"last_name\":\"James\",\"fql_query_response_Id\":0,\"LIFEID\":null}


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
+3
source share
4 answers

This Firebug shows a string containing JSON in this string representation. Think of it as JSON encoding a string containing JSON. Rather, if you put JSON in a string literal in your Javascript, it would look like this.

. .

+3

, Firebug escape-. , JSON ? . , JSON?

+1

.

console.dir({'result':result});

, , .

Firebug , / / ...

var temp = {pasted-string-here}
//var temp = "[{\"uid\":\"516219026\",\"pic\":\"http://profile.ak.net/\", ... }]"
var val = JSON.parse(temp);
console.debug({"val":val});
+1

, JSON, JSON jquery, , jquery .

+1

Source: https://habr.com/ru/post/1730920/


All Articles