This project is read-only.

Newbie question

Jan 27, 2015 at 6:41 AM
First off, THANK YOU!

I need to be able to execute scripts with JSON objects, and handle them as .Net dynamic objects. For instance, if I have a script like this:
var script = @"person = {'firstName':'Mikael', 'lastName':'Hakansson'};";
var v8Engine = new V8Engine();

var person = new ExpandoObject();
v8Engine.GlobalObject.SetProperty("person", person);
Handle result = v8Engine.Execute(script);
After executing the script; I'd like to be able to work with the result as a dynamic type:
var fullName = person.firstName + " " + person.lastName;
Is this possible, and if not, is there another way to extract variables as dynamic objects?
Thanks
Mikael
Jan 27, 2015 at 2:49 PM
Your welcome. ;)

See my comments at the bottom here, and take a look at the link to the source code:
https://v8dotnet.codeplex.com/discussions/577960
Marked as answer by wmmihaa on 1/27/2015 at 11:20 PM
Jan 28, 2015 at 7:20 AM
So something like this:
var script = @"person = {'firstName':'Mikael', 'lastName':'Hakansson'};";
var v8Engine = new V8Engine();

Handle result = v8Engine.Execute(script);
dynamic person = v8Engine.GlobalObject.GetProperty("person");

var fullName = (string)person.firstName + " " + (string)person.lastName;
Thank you.
Marked as answer by wmmihaa on 1/27/2015 at 11:20 PM
Jan 28, 2015 at 4:18 PM
Correct. :). You can build a class with properties to wrap the JSON object and just pull out the values using that method.