rcdmk / aspJSON

A fast classic ASP JSON parser and encoder for easy JSON manipulation to work with the new JavaScript MV* libraries and frameworks.
MIT License
203 stars 89 forks source link

parse doesn't seem to be working #1

Closed frumbert closed 9 years ago

frumbert commented 11 years ago

First example - valid json (according to jsonlint) - when debug is on it doesn't show the first value of "text" but it does the second. serialise doesn't show any data.

Dim oStrings : Set oStrings = new Json
oStrings.debug = true
oStrings.parse "[{""key"":""PrTestLiteral"",""text"":""Test""}, {""key"":""XsNavPrev"",""text"":""« Previous Question""}]"
oStrings.Write()

second example - same string except with the two values reversed. Now it shows both key/text pairs in the debug log, but still nothing when you serialise it.

Dim oStrings : Set oStrings = new Json
oStrings.debug = true
oStrings.parse "[{""key"":""XsNavPrev"",""text"":""« Previous Question""}, {""key"":""PrTestLiteral"",""text"":""Test""}]"
oStrings.Write()

third example - shows that the first value in a nested pair doesn't get saved, and that subsequent pairs can be incorrectly identified as being a "duplicate value" for the "visible" property. Note double-quoting in example is due to how vbscript likes it; it evaluates to valid json.

dim data
data = "{" & _
        """menu"": {" &_
            """entrees"": {" &_
            "    ""label"": ""Entrees""," &_
            "    ""visible"": true" &_
            "}," &_
            """mains"": {" &_
            "    ""label"": ""Mains""," &_
            "    ""visible"": false" &_
            "}," &_
            """desserts"": {" &_
            "    ""label"": ""Indulgencess""," &_
            "    ""visible"": true," &_
            "    ""chocolates"":6" &_
            "}" & _
        "}" & _
       "}"

Dim oJson : Set oJson = new Json
oJson.debug = true
oJson.Parse data
rcdmk commented 9 years ago

Hi. Sorry for being late. Somehouw I've not got any notifications for this and other Issues.

I've done some work since this.

Maybe this was already been fixed, but I will sure take a look at it.

Thank you!

rcdmk commented 9 years ago

There are 2 problems with your example that are entirely my fault: one bug and one mislead.

First, the bug is fixed now. The values of the objects inside the root array where being added to the array instead of the object.

Second, while using the parse function on a string representing an object parses the result and populate the actual object, parsing an array returns a JSONarray object, so you need to set it to a new variable to be able to work with it.

Since there where not place where this was explained, it was not clear you could set the return value of the parse method to another object. This was added as a cooment on the readme.md

set objArray = objString.parse("[{...},{...},...]")
objArray.write()

The third issue still have to be fixed and I will try to fix this as soon as I can.

rcdmk commented 9 years ago

All fixed now. Thanks.