login about faq

I am trying to create a json array like the one from DataTables.net.

Set oJ = Server.CreateObject("Chilkat_9_5_0.JsonArray")
Response.Write oJ.version       'returns 9.5.0.58
s = oJ.AddArrayAt(-1)       'returns 0

'   First Child
Set oChild = oJ.ArrayAt(0)
Response.Write TypeName(oChild)       'returns 'Nothing'

asked Apr 21 at 12:58

emartinson's gravatar image

emartinson
148162030


Thanks, I'll give it a try. (I thought I had fixed this issue, but maybe not. I'll double-check..)

link

answered Apr 22 at 11:26

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

The issue I was thinking about was not the same.

This was not properly documented, and I'll try to make this clear in the documentation: The JsonArray object is not a standalone object. Semantically, it should never be created via CreateObject. It must always be part of a JsonObject For example, examine the JSON spec here: http://www.json.org/

The JSON object is the top-level construct of any JSON document. An array is one particular type of value that can be held within a JSON object.

Therefore, you would do this:

Set oJ = Server.CreateObject("Chilkat_9_5_0.JsonObject")
s = oJ.AddArrayAt(-1)
Set oChild = oJ.ArrayAt(0)
Response.Write TypeName(oChild)

' To add an array inside the array: s = oChild.AddArrayAt(-1) Set oChild2 = oChild.ArrayAt(0) Response.Write TypeName(oChild2)

link

answered Apr 22 at 12:18

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

chilkat, I this there is an issue with JsonObject.ArrayAt. First is requires a second argument where JsonArray.ArrayAt only takes the index.

Set oJ = Server.CreateObject("Chilkat_9_5_0.JsonObject")
oJ.AddArrayAt -1, ""  <- Extra Argument
Set oChild = oJ.ArrayAt(0)

' To add an array inside the array:
oChild.AddArrayAt -1
Set oChild2 = oChild.ArrayAt(0)
oChild2.AddStringAt -1, "One"
oChild2.AddStringAt -1, "Two"
oChild2.AddStringAt -1, "Three"

The output is this.

{                <- I think the key/value on the line below is changing this it a object
  "": [          <- the extra argument shows here
    [
      "One",
      "Two",
      "Three"
    ]
  ]
}
link

answered Apr 22 at 14:08

emartinson's gravatar image

emartinson
148162030

Yes, I made a mistake in my first response. JsonObject.AddArrayAt takes two arguments: the index and name. JsonArray,.AddArray At only has 1 argument: the index.

    Set oJ = Server.CreateObject("Chilkat_9_5_0.JsonObject")
    oJ.AddArrayAt -1, "abc" 
    Set oChild = oJ.ArrayAt(0)

' To add an array inside the array:
    oChild.AddArrayAt -1
    Set oChild2 = oChild.ArrayAt(0)
    oChild2.AddStringAt -1, "One"
    oChild2.AddStringAt -1, "Two"
    oChild2.AddStringAt -1, "Three"
The output is this.
    {               
      "abc": [         
        [
          "One",
          "Two",
          "Three"
        ]
      ]
    }
  
link

answered Apr 22 at 15:55

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Is there a way to get the first array unnamed? I am looking to create an array or arrays

Something like this?

{               
  [         
    [
      "One",
      "Two",
      "Three"
    ],
    [
      "apple",
      "banana",
      "orange"
    ]
  ]
}
link

answered Apr 27 at 16:41

emartinson's gravatar image

emartinson
148162030

That's not valid JSON. See the JSON specification, which is very simple: http://www.json.org/

JSON is a JSON object, which contains 0 or more members, where each member is a pair. A pair is a string : value, where the value can be several different things (string, array, number, another object, etc.)

(Apr 27 at 17:16) chilkat ♦♦

Okay, I think I understand. I looked at JSON Validator and changed my string until it was happy. This is what I came up with and it happens to match the example data at Data Tables. Can this be done with JSONObject?

[
    [
        "One",
        "Two",
        "Three"
    ]
    ,
    [
        "apple",
        "banana",
        "orange"
    ]

]
link

answered Apr 27 at 18:05

emartinson's gravatar image

emartinson
148162030

Here's a new build (pre-release) where I've added the Emit method to JsonArray:

32-bit Download: http://www.chilkatsoft.com/download/preRelease/ChilkatAx-9.5.0-win32.zip
64-bit Download: http://www.chilkatsoft.com/download/preRelease/ChilkatAx-9.5.0-x64.zip

(The JsonArray object is obtained from the JsonObject that contains it. If you wish to emit non-compact JSON from JsonArray, set the JsonOjbect.EmitCompact = 0 prior to getting the JsonArray object.)

link

answered Apr 27 at 18:51

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×96
×17

Asked: Apr 21 at 12:58

Seen: 506 times

Last updated: Apr 27 at 18:51

powered by OSQA