我在C#中使用Awesomium,我正在将变量拖出javascript。
运行的代码:
if (GotCategories == false) {
if (WebBrowser.ExecuteJavascriptWithResult("finished").ToString() == "true" && WebBrowser.IsDocumentReady == true) {
int Level1Len = Convert.ToInt32(WebBrowser.ExecuteJavascriptWithResult("all_categories.length").ToString());
for (int i = 0; i < Level1Len - 1; i++) {
string Level1 = WebBrowser.ExecuteJavascriptWithResult("all_categories[" + i + "].title");
string Level1ID = WebBrowser.ExecuteJavascriptWithResult("all_categories[" + i + "].id");
TreeNode treenode = new TreeNode(Level1);
CatsTree.Nodes.Add(treenode);
int Level2Len = Convert.ToInt32(WebBrowser.ExecuteJavascriptWithResult("all_categories[" + i + "].sub.length").ToString());
for (int j = 0; j < Level2Len; j++) {
string Level2 = WebBrowser.ExecuteJavascriptWithResult("all_categories[" + i + "].sub[" + j + "].title");
string Level2ID = WebBrowser.ExecuteJavascriptWithResult("all_categories[" + i + "].sub[" + j + "].id");
treenode = new TreeNode(Level2);
CatsTree.Nodes[i].Nodes.Add(treenode);
int Level3Len = Convert.ToInt32(WebBrowser.ExecuteJavascriptWithResult("all_categories[" + i + "].sub[" + j + "].sub.length").ToString());
for (int k = 0; k < Level3Len; k++) {
string Level3 = WebBrowser.ExecuteJavascriptWithResult("all_categories[" + i + "].sub[" + j + "].sub[" + k + "].title");
string Level3ID = WebBrowser.ExecuteJavascriptWithResult("all_categories[" + i + "].sub[" + j + "].sub[" + k + "].id");
treenode = new TreeNode(Level3);
CatsTree.Nodes[i].Nodes[j].Nodes.Add(treenode);
if (WebBrowser.ExecuteJavascriptWithResult("all_categories[" + i + "].sub[" + j + "].sub[" + k + "].sub.length").IsInteger == true) {
string Level4Len = Convert.ToInt32(WebBrowser.ExecuteJavascriptWithResult("all_categories[" + i + "].sub[" + j + "].sub[" + k + "].sub.length").ToString());
虽然发生了一个奇怪的问题..
如果我运行它现在是怎么回事Level4Len抛出异常错误
输入字符串的格式不正确。
虽然..奇怪的是,如果我放一个MessageBox.Show(Level4Len);
我没有收到错误和...以及所显示的输出完全正常,因为它们应该是。
我见过的最奇怪的事情......