I have a web page, when on button click returning javascript object.
<input type="button" value="JSON Object" onclick="JSONObjectTest(user1)"
var user1 = { "name" : "myname", "title": "mytitle", "salary" : null};
In C# application, I am loading this web page which contains the above code using web browser. And implemented the below code in C#
this.webBrowser.ObjectForScripting = new JavascriptEventHandler();
This code in DocumentCompleted
var scriptBlock = webBrowser.Document.CreateElement("script");
var sb = new StringBuilder();
sb.Append("window.JSONObjectTest=function(param){window.external.JSONObjectEvent(param);}");
scriptBlock.SetAttribute("type", "text/javascript");
scriptBlock.SetAttribute("text", sb.ToString());
webBrowser.Document.Body.AppendChild(scriptBlock);
This is code for JavascriptEventHandler(ObjectForScripting) Class
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[ComVisible(true)]
public class JavascriptEventHandler
{
public void JSONObjectEvent(object param)
{
}
}
I was able to load the web page perfectly. And when a button is clicked on webpage I was able to hit this method - JSONObjectEvent in C#.
My problem here is, I want to deserialize the javascript object into c# class. I am getting object type as System._COMObject.
How to deserialize it? Please help.
Using Newtosnsoft.Json to deserailize.
NOTE : I will be getting javascript object only not in string. If I pass JSON.Stringify(user1) from web page, I can able to deserialize it. But if it is javascript object I cannot able to deserialize.