I am new to JSON, and want to make simple JSON object using StringBuilder which would be queried by a jQuery Ajax call.
[WebMethod]
public static string GetmyJSON()
{
StringBuilder sb = new StringBuilder();
sb.Append("{firstname: \"Manas\",").Append("lastname : \"Tunga\"").Append("}");
return sb.ToString();
}
In my client-side code i have:
.ajax({
type: "POST",
url: "simplePage.aspx/GetmyJSON",
data: "{}",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (data) {
alert(data.d.firstname);
} // end of sucess
}); // End of ajax
But my alert message shows 'undefined' instead of 'Manas'. Is it possible to return a JSON object using StringBuilder?
\"to', ether change it to\\\"{"id":10}