1

我正在使用 Jint 在 C# 应用程序中评估 JavaScript。我的 JS 返回一个字符串数组:

return ["blah", "blah", "blah"];

但是一旦我回到 C# 中,我不确定如何正确使用该数组:

Object result = e.Execute (javaScript).Invoke("jsFunction", answers).ToObject();
string[] resultAsStrings = ???;

这是调试器的样子:

在此处输入图像描述

4

1 回答 1

1

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

于 2015-09-23T16:19:14.723 回答