I'm using Jint to evaluate JavaScript within a C# application. My JS returns an array of strings:
return ["blah", "blah", "blah"];
But I'm not sure how to properly use that array once I'm back in C#:
Object result = e.Execute (javaScript).Invoke("jsFunction", answers).ToObject();
string[] resultAsStrings = ???;
Here's what the debugger looks like:
You can just cast the result of ToObject()
to an object[]
in this case.
Here are the transformations that ToObject()
applies when facing a JavaScript value:
undefined
: null
null
: null
Boolean
: bool
String
: string
Number
: double
Array
: object[]
with each element itself converted using ToObject()
Date
: DateTime
Function
: Func<JsValue, JsValue[], JsValue>
RegExp
: Regex
Object
: dynamic
with all the properties of the object converted using ToObject()
If no type is matching, it throws ArgumentOutOfRangeException
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.