Sample code for 30+ languages & platforms
DataFlex

JSON AppendObject2 Example

Demonstrates the AppendObject2 function.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoJson
    Boolean iSuccess
    Variant vJObj
    Handle hoJObj
    String sTemp1

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComLoad Of hoJson '{ "name": "John", "marbles": 100 }' To iSuccess

    // Append an empty object named "addr"
    Get Create (RefClass(cComChilkatJsonObject)) To hoJObj
    If (Not(IsComObjectCreated(hoJObj))) Begin
        Send CreateComObject of hoJObj
    End
    Get pvComObject of hoJObj to vJObj
    Get ComAppendObject2 Of hoJson "addr" vJObj To iSuccess

    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1
    // Expected output is:   {"name":"John","marbles":100,"addr":{}}

    // Add members to the object.
    Get ComAppendString Of hoJObj "street" "1200 Elm St." To iSuccess
    Get ComAppendString Of hoJObj "city" "Springfield" To iSuccess
    Get ComAppendInt Of hoJObj "zip" 60606 To iSuccess

    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1
    // Expected output is:  {"name":"John","marbles":100,"addr":{"street":"1200 Elm St.","city":"Springfield","zip":60606}}


End_Procedure