(VBScript) JSON AppendObject Example
Demonstrates the AppendObject function.
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.JsonObject")
set json = CreateObject("Chilkat.JsonObject")
success = json.Load("{ ""name"": ""John"", ""marbles"": 100 }")
' Append an empty object named "addr"
' jObj is a Chilkat.JsonObject
Set jObj = json.AppendObject("addr")
outFile.WriteLine(json.Emit())
' Expected output is: {"name":"John","marbles":100,"addr":{}}
' Add members to the object.
success = jObj.AppendString("street","1200 Elm St.")
success = jObj.AppendString("city","Springfield")
success = jObj.AppendInt("zip",60606)
outFile.WriteLine(json.Emit())
' Expected output is: {"name":"John","marbles":100,"addr":{"street":"1200 Elm St.","city":"Springfield","zip":60606}}
outFile.Close
|