How to pass Json serialized object to javascript (ASP.NET C#)
i have a method that returns a list of serialized objects in my page code behind
private string Get()
{
JavaScriptSerializer jsonSerialiser = new JavaScriptSerializer();
string jsonString = SerializeToJas开发者_JAVA技巧on(UnavailabilityBusiness.Get(new DateTime()));
return jsonString ;
}
i would like to pass this serialized objects to javascript
function getJson()
{
??????
}
How do I do it?
You could write them out as a script, typically leveraging ClientScript.
You would want to take care to register the script so that it renders before the consuming script.
Looks like this guy wrote a utility class to do what you're trying to do (Code Project Link).
I have't really looked at it but you can get his source and have a look.
Good luck,
Patrick.
精彩评论