jsexecutor class : Parse(string) method

Description

Parses the string that returned as the result of the JavaScript and returns the type and value.

Syntax

instance.Parse(string ret)

Arguments

ClassNameDescription
stringretReturn value from JavaScript.

Return value

ClassDescription
pairThe parsed type name and value.

Sample code

1:

string jscode = "return 100;";

2:

jsexecutor jse;

3:

string result = jse.Execute(jscode); // Returns 100 as string.

4:

pair resultSet = jse.Parse(result);

5:

string className = resultSet.First; // "int"

6:

int value = resultSet.Second; // 100

Notes

Return values from the JavaScript are converted to strings and returned. This method parses the string and returns an instance of the pair class that stored class name and value.

If it can be converted to an integer and the converted value falls within the range of int, First is "int" and Second is an instance of the int class. If it exceeds the range of int, First is "long" and Second is an instance of the long class.

If the number cannot be converted to an integer, First is "real" and Second is an instance of the real class.

If it can be converted to a boolean value, First is "bool" and Second is an instance of the bool class.

If the string is enclosed in double quotes, First is "string" and Second is an instance of the string class. The enclosed double quotes will remove.

If the string is "null" or unevaluable, First is "null" and Second is an instance of the dummy class.

Links for reference

None.

Copyright © Cooker All rights reserved.