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
204 stars 89 forks source link

Fails to parse object array (even your own example) #78

Closed rokdevil closed 4 years ago

rokdevil commented 6 years ago

Unless I'm missing something... jsonString = "[{ ""strings"" : ""valorTexto"", ""numbers"": 123.456, ""arrays"": [1, ""2"", 3.4, [5, 6, [7, 8]]], ""objects"": { ""prop1"": ""outroTexto"", ""prop2"": [ { ""id"": 1, ""name"": ""item1"" }, { ""id"": 2, ""name"": ""item2"", ""teste"": { ""maisum"": [1, 2, 3] } } ] } }]"

will fail on: set js = new JSONObject js.parse(jsonString)

Output:

  • Load string: "[{ "strings": "valorTexto", "numbers": 123.456, "arrays": [1, "2", 3.4, [5, 6, [7, 8]]], "objects": { "prop1": "outroTexto", "prop2": [{ "id": 1, "name": "item1" }, { "id": 2, "name": "item2", "teste": { "maisum": [1, 2, 3] } }] }}]"
  • --   |

  • Enter init
  •   |
  • Create array
        |
    • Added to parent object
    •   |
    • Set as root
    •   |
    • Open object value
    •   |
    • Enter init
    •   |
    • Create object
          |
      • Open key
      •   |
      • Close key: "strings"
      •   |
      • Open value for "strings"
      •   |
      • Open string value
      •   |
      • Close string value: "valorTexto"
      •   |
      • Value added to array: "strings": valorTexto
      •   |
      • New value
      •   |
      • Open string value
      •   |
      • Close string value: "numbers"
      •   |
      • Value added to array: "strings": numbers
      •   |
      • New value
      •   |
      • Open string value
      •   |
      • Close string value: "arrays"
      •   |
      • Value added to array: "strings": arrays
      •   |
      • New value
      •   |
      • Open string value
      •   |
      • Close string value: "2"
      •   |
      • Value added to array: "strings": 2
      •   |
      • New value
      •   |
      • Open numeric value
      •   |
      • Close numeric value: 3.4
      •   |
      • Value converted to number
      •   |
      • Value added to array: "strings": 3.4
      •   |
      • New value
      •   |
      • Open array value
      •   |
      • Enter init
      •   |
      • Create array
            |
        • Added to parent array
        •   |
        • Open numeric value
        •   |
        • Close numeric value: 5
        •   |
        • Value converted to number
        •   |
        • Value added to array: "strings": 5
        •   |
        • New value
        •   |
        • Open numeric value
        •   |
        • Close numeric value: 6
        •   |
        • Value converted to number
        •   |
        • Value added to array: "strings": 6
        •   |
        • New value
        •   |
        • Open array value
        •   |
        • Enter init
        •   |
        • Create array
              |
          • Added to parent array
          •   |
          • Open numeric value
          •   |
          • Close numeric value: 7
          •   |
          • Value converted to number
          •   |
          • Value added to array: "strings": 7
          •   |
          • New value
          •   |
          • Open numeric value
          •   |
          • Close numeric value: 8
          •   |
          • Value converted to number
          •   |
          • Value added to array: "strings": 8
          •   |
          • Close array
        •   |
        • Close array
      •   |
      • Close array
    •   |
    • New key
    •   |
    • Open key
    •   |
    • Close key: "objects"
    •   |
    • Open value for "objects"
    •   |
    • Open object value
    •   |
    • Enter init
    •   |
    • Create object
          |
      • Added to parent object: "objects"
      •   |
      • Open key
      •   |
      • Close key: "prop1"
      •   |
      • Open value for "prop1"
      •   |
      • Open string value
      •   |
      • Close string value: "outroTexto"
      •   |
      • Value added: "prop1"
      •   |
      • New key
      •   |
      • Open key
      •   |
      • Close key: "prop2"
      •   |
      • Open value for "prop2"
      •   |
      • Open array value
      •   |
      • Enter init
      •   |
      • Create array
            |
        • Added to parent object
        •   |
        • Open object value
        •   |
        • Enter init
        •   |
        • Create object
              | A property already exists with the name: prop2

  • rcdmk commented 6 years ago

    Hi. Hum... This is strange. I'll check it soon.

    Btw, are you running the latest version?

    wimp1 commented 6 years ago

    "Me too"! I have a multirow database table dumped on me as JSON, and your code sees the first column "Id" twice and stops. I like the rest of it, though. But most of all I'd like something to put the JSON table into a database table.

    I see that the propertynames are stored in the array i_properties in JSONobject. This requires that each table row (with of course repeated property names) be a separate JSONobject with its own i_properties array, though the parsing is a JSONobject method, not a jsonArray method, so maybe it's a "scope" thing. (Hope this helps).

    rcdmk commented 6 years ago

    Hi. When you parse a JSON array, the resulting object contains a JSON array property that holds each array value. The properties array is specific for each object and should work as expected, unless you have invalid JSON with repeated property names in a single object. Can you share a simple copy or example of what you are trying to parse?

    rcdmk commented 6 years ago

    Also, can you please try older versions to see if this works? I'm suspecting this was introduced in one of the last 5 releases.