Click here to Skip to main content
16,017,899 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my code in which I am getting data of dictionary from a server method in the form of



{"Peter Pan":"peterpan@pan.de","Molly":"molly@yahoo.com","Don Corleone":"don@vegas.com"}

code:
$.ajax({
type: "POST",
url: "Default.aspx/GetPeople",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
var Mydata = result.d;
$("#dictionary").append(Mydata);
}
});
});
});

how can I show them in a 2DArray format in html Div with the help of .each() function in jquery.
Please Answer@@
Posted

You can do like this:

JavaScript
$.each(Mydata, function(key, val){
// This function will called for each key-val pair.
// You can do anything here with them.

});


Hope, this will help you.
 
Share this answer
 
Friend try it like this :
$.parseJSON(msg), It will parse automatically and convert it in array type object.

My Ajax call :

HTML
// Add the page method call as an onclick handler for the div.
    $("#oneRecord").click(function () {
        alert();
        $.ajax({
            type: "GET",
            url: "http://mysite/MyWcfService.svc/GetCustmer",
            data:"id=0",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            processData: true,
            success: function (msg) {
                // Replace the div's content with the page method's return.
                //debugger;
                msg = $.parseJSON(msg);
                 $(msg).each(function(index, record) {
                    $("#singleresult").append("<table width='250'><tr><th>ID</th><th>Name</th><th>Designation</th><th>Salary</th></tr>");
                    $("#singleresult").append("<tr><td>"+record.CustID+"</td><td>"+record.FirstName+"&nbsp;"+record.LastName+"</td><td>"+record.Designation+"</td><td>"+record.Salary+"</td></tr>");
                    $("#singleresult").append("</table>");
                 });

                //$("#singleresult").text(msg);
            },
            error: function (err){
            //debugger;
                alert(err);
                $("#singleresult").text(err.statusText);
            }
        });
    });



My result data from service is :

"{\"BoolValue\":true, \"CustID\":1,\"Designation\":\"Analyst\", \"FirstName\":\"A1\",  \"LastName\":\"B1\", \"Salary\":3093.9}"
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900