0

Im trying to parse a json string in classic asp. A found a useful script referenced on stackoverflow: https://github.com/douglascrockford/JSON-js/blob/master/json2.js

when calling the 'parse' function I get an error:

<script language="JScript" runat="server" src="json2.js"></script>

'line 144 of my script


Set myJSON = JSON.parse(versionsStr)


Microsoft VBScript runtime error '800a01a8' 

Object required: '[string: "[{"self":"https://dc"]' 

/libs/asp/common/jira_api.asp, line 144 

Here is my json string (versionStr):

 [{"self":"https://server.com:8343/rest/api/2/version/10300","id":"10300","description":"baseline version","name":"1.0","archived":false,"released":true,"releaseDate":"2013-11-07","userReleaseDate":"07/Nov/13"},{"self":"https://server.com:8343/rest/api/2/version/10301","id":"10301","description":"sample version","name":"1.1.0","archived":false,"released":false},{"self":"https://server.com:8343/rest/api/2/version/10302","id":"10302","name":"3.0.0","archived":false,"released":false}]

Im guessing that the script Im using is expecting a json object, but my calls to the jira API are returing json strings. Does someone have a solution that parses a json string into a classic asp array?

7
  • Do these offer any clues? stackoverflow.com/questions/1019223/… , code.google.com/p/aspjson Commented Nov 24, 2013 at 1:14
  • I was there already. That led me to the json2.js script Im using. Commented Nov 24, 2013 at 1:20
  • Where is versionsStr coming from? Commented Nov 24, 2013 at 1:36
  • versionStr is the json string Im. I added it to my question. Commented Nov 24, 2013 at 1:54
  • Why is this tagged "VBScript"? Commented Nov 24, 2013 at 10:45

1 Answer 1

1

You are right. You can call javascript code from vbscript code. And you can use the json2.js script, BUT what you can not do is pass arrays from javascript to vbscript and use indexed access to them.

Save this as test.wsf and run with cscript test.wsf (make sure json2.js is in the same directory).

<?XML version="1.0" standalone="yes" encoding="utf-8" ?>
<package>
<job id="test" prompt="no">
<?job error="true" debug="true" timeout="10" ?>

<script language="Javascript" src="json2.js" />

<script id="main" language="VBScript">
<![CDATA[

    Dim versionStr
        versionStr ="[{""self"":""https://server.com:8343/rest/api/2/version/10300"",""id"":""10300"",""description"":""baseline version"",""name"":""1.0"",""archived"":false,""released"":true,""releaseDate"":""2013-11-07"",""userReleaseDate"":""07/Nov/13""}" + _ 
                    ",{""self"":""https://server.com:8343/rest/api/2/version/10301"",""id"":""10301"",""description"":""sample version"",""name"":""1.1.0"",""archived"":false,""released"":false}" + _ 
                    ",{""self"":""https://server.com:8343/rest/api/2/version/10302"",""id"":""10302"",""name"":""3.0.0"",""archived"":false,""released"":false}]"

    Dim myJSON 
        Set myJSON = JSON.parse(versionStr)

    Dim numVersions
        numVersions = myJSON.length

    Dim i, version
        For i = 1 to numVersions
            Set version = myJSON.shift()
            WScript.Echo version.self
        Next


]]>
</script>

</job>
</package>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.