C# - Read JavaScript file and access variable -


I have a javascript file that contains variables defined and they have values ​​specified. Is it possible to read .js file with C # and easily recover variables and prices? I know what variable names will be, but the values ​​will be a JSON string. I hope that I do not have the support of regular expressions.

EDIT: I do not have control over the content of the JavaScript file. A third party takes the file to a location and I have to choose it, read it, and paste it.

Edit 2: Fine, forget I mentioned Jason. Actually there is nothing to do with my question ... which is not a simple solution at this point. So I went through the line to read the .js file line, search for variable names and get value. Code below for reference. Using

(StreamReader r = new streamrider ("myFile.js")) {while (r.Peek ()> = 0) {var line = r.ReadLine ( ); If (line.inx ("myVariableName")> gt; -1) {var arr = line.split ("="); Var variable = arr [0]. Trim (); Var Value = ARR [1] Trim (); }}}}

I had a similar problem with the browser helper object I was web generated Create data to remove data and store it in local file system.

I have done the following to use JS values:

  mshtml.IHTMLDocument document = (mshtml .IHTMLDocument) this.Explorer.IWebBrowser_Document; Object script = document.Script; If (Script! = Null) {// Call: var jsvar = script.GetType () InvokeMember ("eval", binding flags, invocamath, blank, script, new object [] {"HIS_VisitNumber"}); // Cast ... _StroySize = (string) JS; // Release the script object, and perhaps the document object. Marshal.ReleaseComObject (script); }  

Here it is. Explorer is an explorer object that is available through the Band Object (BHO).

But obviously, this approach is possible only if you will be able to take advantage of a browser (IE) which has all the facilities to load and execute JS.

If you can not do this, I suppose you have a complete C #JS Parser or do I not understand your question correctly?

In the latter case, you


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -