I have a Silverlight class marked with ScriptableType and ScriptableMember and I expect that I can pass the object from Silverlight to javascript. When I call JSON.stringify (in javascript), I expect to get a JSON representation of the object, but all I get is{}
A class is defined as:
[ScriptableType()]
public class MyEvent
{
[ScriptableMember(ScriptAlias = "eventContent")]
public int EventContent { get; set; }
}
I am passing an object from Silverlight as follows:
var jsonObject = new MyEvent { EventContent = 1 };
HtmlPage.Window.Invoke("publishValue", topic, jsonObject);
And in javascript, I do the following:
alert(topic);
alert(jsonObject);
alert(JSON.stringify(jsonObject));
When I use the debugger, I see only jsonObjectby type Object, but the call alert(jsonObject)returns the correct type, and if I access the property jsonObject.eventContent, I get the correct value back, but it doesn’t serialize the series correctly using JSON.stringify.
Someone say what I'm doing wrong?
I do not want to serialize the object in Silverlight before submitting to javascript.
AWC