I wouldn't mess with any of the Homer stuff. Jamal abandoned that code long
ago. Instead, to parse JSON using VBScript, you can do something like this:
First, get your JSON into a variable of some sort. For example, I have a text
file that includes the following JSON string:
{
"Image": {
"Width": 800,
"Height": 600
}
}
I'll load that using this:
Set fsObj = CreateObject("Scripting.FileSystemObject")
Set f = fsObj.OpenTextFile("json.txt", 1)
json = f.ReadAll()
I now have a variable, json, that contains my JSON text. Next, I can parse it
into an object using the following:
Set html = CreateObject("htmlfile")
Set win = html.parentWindow
win.execScript "var json = " & json, "JScript"
Set jsonObj = win.json
If you examine the typename of jsonObj, you'll find it to be JscriptTypeInfo.
You can then access the properties of the object using standard dot notation,
like this:
MsgBox jsonObj.image.width
You'll get a message box containing:
800
The htmlfile object is the Microsoft HTML Object Library, and it handles
(obviously) parsing JSON.
Thanks,
Aaron
--
Aaron Smith
Web Development * App Development * Product Support Specialist
Ai Squared * 725 Airport North Office Park, Fort Wayne, IN 46825
260-489-3671 * www.aisquared.com
To insure that you receive proper support, please include all past
correspondence (where applicable), and any relevant information pertinent to
your situation when submitting a problem report to the Ai Squared Technical
Support Team.
> -----Original Message-----
> From: Scripting [mailto:scripting-
> [email protected]] On Behalf Of Chip
> Orange via Scripting
> Sent: Friday, August 21, 2015 9:47 AM
> To: Window-Eyes Scripting List <[email protected]>
> Subject: use of HomerJS
>
> Hi all,
>
> At one time I got a copy of a java script named HomerJS (written by Jamal
> Mazrui). It's not really documented, and so I'm not sure if he ever published
> it, or if he included it with homer, or if he just sent me a copy. I can't
> find any
> documentation or examples.
>
> It is supposed to let you call the java script Eval() function from VBScript;
> however, every thing I've tried has failed. The java script which needs to be
> running in order for this to be used is placed below; I would appreciate it if
> anyone here who knows java script could take a look and see if this (as
> written) can even work, and if so give me a VBScript example showing how
> to use it, or tell me it has a problem so that I'll stop!
>
> (I need this because I need to interface with a RESTful app on the web which
> only returns JSON results), and I need to do so using VBScript).
>
> Thanks.
>
> Chip
>
> function HomerJS() {
> this.Eval = Eval
> } // HomerJS constructor
>
> function Eval(sText) {
> var v
>
> try {
> v = eval(sText)
> }
> catch (e) {
> v = "undefined"
> }
> return v
> } // Eval method
>
> ClientInformation.ScriptName = "HomerJS"
> ClientInformation.ScriptVersion = "1.1"
> ClientInformation.ScriptDescription = "Access the eval function of JScript at
> runtime."
> ClientInformation.ScriptHelp = "HomerJS is a shared object that provides
> access to the eval function of JScript at runtime."
>
> SharedObjects.Register("org.NonvisualDevelopment.HomerJS", new
> HomerJS)
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.window-eyes.com/private.cgi/scripting-window-
> eyes.com/attachments/20150821/b478923d/attachment.htm>
> _______________________________________________
> Any views or opinions presented in this email are solely those of the author
> and do not necessarily represent those of Ai Squared.
>
> For membership options, visit http://lists.window-
> eyes.com/options.cgi/scripting-window-
> eyes.com/asmith%40aisquared.com.
> For subscription options, visit http://lists.window-
> eyes.com/listinfo.cgi/scripting-window-eyes.com
> List archives can be found at http://lists.window-
> eyes.com/private.cgi/scripting-window-eyes.com
_______________________________________________
Any views or opinions presented in this email are solely those of the author
and do not necessarily represent those of Ai Squared.
For membership options, visit
http://lists.window-eyes.com/options.cgi/scripting-window-eyes.com/archive%40mail-archive.com.
For subscription options, visit
http://lists.window-eyes.com/listinfo.cgi/scripting-window-eyes.com
List archives can be found at
http://lists.window-eyes.com/private.cgi/scripting-window-eyes.com