Rank: Member Groups: Member
Joined: 5/20/2015 Posts: 11
|
Hi,
I just started using EO.WebBrowser, I am using Webforms and c# (Need to implement googlemaps.api replacing the curent mapping system)
I need to pass some JSON Objects to Javascript to work with. Used Newtonsoft.Json to create the objects and now am looking to pass em on to the EO.webview containing a javascript-function like so.
//////// public void lookupAddress(string address) { string temp = address; Location loc = coder.GeocodeAddress(temp);
int zoomlevel = coder.calcZoom(loc); JObject rss = new JObject( new JProperty("lat", loc.getLatitude().ToString().Replace(",", ".")), new JProperty("longt", loc.getLongitude().ToString().Replace(",", ".")), new JProperty("zoomlevel", zoomlevel), new JProperty("description", loc.getAddressFull()), new JProperty("imagepath", crossImagePath));
EO.WebBrowser.JSObject window = EO_WebView.GetDOMWindow(); //Get the JavaScript function EO.WebBrowser.JSFunction jsAddMarker = (EO.WebBrowser.JSFunction)EO_WebView.EvalScript("RSSAddMarkers"); //Call the function jsAddMarker.Invoke(window, new Object[] { rss }); } //////////////////////////
When running the application visual studio gives me the folowing when trying to execute the invoke(): Object '{ .... } of type 'Newtonsoft.Json.Linq.JObject' can not be passed to JavaScript code.
Should I be working with something else to get somekind of JSON-objects through??
I probably missed something, but if anyone could give me some tips on handling this that would be awesome.
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, You can not pass a .NET object directly into the JavaScript excepts for primative types (theorartically we could automatically convert a .NET object into a JavaScript object under the hood but that would come with a performance penalty). Instead of passing JObject to the JavaScript, you can serialize it into a JSON string and then pass that string into JavaScript. You can then parse it back into JSON object with the EO.WebBrowser's built in JSON support in your JavaScript:
Code: JavaScript
//Parse JSON string back to an object in JavaScript
var jobj = JSON.parse(your_json_string);
Note here JSON is the built-in JSON support provided by the browser engine. This is also much more efficient. Thanks!
|
Rank: Member Groups: Member
Joined: 5/20/2015 Posts: 11
|
Works like a charm! Thanks for the help!
|