Silverlight error while passing JSON object?

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

+3
2

!

, , Silverlight javascript:

[ScriptableType()] 
public class MyEvent 
{ 
    [ScriptableMember(ScriptAlias = "eventContent")] 
    public int EventContent { get; set; } 
} 

System.Json namepace JsonObject :

  var ob = new JsonObject
  {
       {"eventContent", 1}
  };

System.Json.JsonObject.

AWC

+2

JSON.stringify for...in. , .

Silverlight - , javascript. ActiveXObject, /. , . , , , IEnumerable foreach , , JavaScript.

, , . , System.Json eval , JavaScript.

+2

Source: https://habr.com/ru/post/1733509/


All Articles