I have following JSON string returned to a page.
{“firstName”:”Bob”,”lastName”:”Gates”,”department”:”Tech”}
I would like to display properties values in a page but I’m having problem.
Here is my jquery ajax
function BuildTable(msg) {
var Person = msg[0];
var table = '<table><tr><td>' + person.firstName + '<td><tr></table>'
$("#temp").html(table);
};
$.ajax({
type: "POST",
url: "../test/json.aspx/testjson",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
BuildTable(msg.d);
}
});
This returns “undefined” although I see JSON string in Firebug.
I can return JSON string by using “msg” instead of “Person.firstName”
How do I display property values in JSON string?
Thank you
A couple things here that seem wrong
you are doing msg.d, however the returned json object doesn’t have a property named ‘d’.
once you pass in msg.d into your BuildTable function you try to use it as an array.
you declare a Person object and then try to reference “person” with lowercase this is also incorrect since js is case sensitive.
UPDATE: