Here is my code:
{
"Persons": [
}
but it actually output
{
"Persons": {
}
I understand it use the dynamic V8ScriptItem to convert the javascript object to host object.
But is there a way to keep array of javascript as also a array or list of host object?
using System;
using Microsoft.ClearScript.V8;
using Newtonsoft.Json;
namespace ConsoleApplication
{
public class Test
{
public void Output(object o)
{
Console.WriteLine(JsonConvert.SerializeObject(o));
}
}
class Program
{
static void Main(string[] args)
{
var engine = new V8ScriptEngine();
engine.AddHostObject("test", new Test());
var script = "var o = {Persons: [{Name :\"John\"}, {Name :\"Joe\"}] }; test.Output(o);";
engine.Execute(script);
}
}
}
I expect that it output {
"Persons": [
{
"Name": "John"
},
{
"Name": "Joe"
}
]}
but it actually output
{
"Persons": {
"0": {
"Name": "John"
},
"1": {
"Name": "Joe"
}
}}
I understand it use the dynamic V8ScriptItem to convert the javascript object to host object.
But is there a way to keep array of javascript as also a array or list of host object?