I have a web application. Inside I have a asmx file “MyWebServices.asmx” where I have a Webmethod that Sends a json object to my WebForm2.aspx. My problem is how to capture this object with Javascript store it and display it with javascript. My code on MyWebServices.asmx :
public class apointment
{
public string Fname{ get; set; }
public string Lname{ get; set; }
public string customerid { get; set; }
}
[WebMethod]
public string myapointment()
{
apointment myapointment1= new apointment();
myapointment1.customerid = "123POW";
myapointment1.Fname = "John";
myapointment1.Lname = "JohnsLname";
System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
string sJSON = oSerializer.Serialize(myapointment1);
return sJSON;
}
My code on .net page Javascript:
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: "services/MyWebServices.asmx/myapointment",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
// Insert the returned HTML into the <div>.
var myrant = data.d;
$('#RSSContent').html(data.d);
}
});
});
</script>
The problem is with this code I am taking a string:
{"Fname":"John","Lname":"JohnsLname","customerid":"123POW"}
How can I convert this string to an object type appointment? Am asking because after that I can displayed correctly on html, I would like to create lists of appointments.