Previous Next

GetJsonObject( ) method (JsonArray)
Gets the JsonObject value of one or more elements as a JsonObject, or as an array of JsonObjects.
Return type:
Access:
Applies to:
 
Syntax 
GetJsonObject( INPUT index AS INTEGER )
 
GetJsonObject( INPUT index AS INTEGER,
               INPUT count AS INTEGER )
When this method is called with one parameter, the value of a single element is returned. Using two parameters directs the AVM to return an ABL array consisting of count elements.
index
An INTEGER identifying the value of the element to be returned. Indexing into JsonArrays is 1-based.
count
An INTEGER specifying the number of elements, starting with the element at index, to be returned in the ABL array.
A JsonError is raised if:
*
index is less than 1, is greater than the length of the JsonArray, or is the Unknown value (?)
*
The sum of index and count is greater than the length of the JsonArray
*
The following example demonstrates the functionality of the GetJSonObject( ) method.
The following is a sample JsonArray:
 
[
    {“OrderNum”: 82, “OrderDate”: “2010-09-20”},
    {“OrderNum”: 83, “OrderDate”: “2010-09-20”}
]
The following is a code fragment that uses the GetJsonObject( ) method:
DEFINE VARIABLE OrderInfo AS LONGCHAR NO-UNDO.
DEFINE VARIABLE OrderArray AS JsonArray NO-UNDO.
DEFINE VARIABLE myOrder AS JsonObject NO-UNDO.
DEFINE VARIABLE myLongchar as LONGCHAR NO-UNDO.
 
/*
 .
 . Set OrderInfo to the JsonArray shown above.
 .
 */
 
OrderArray = CAST(myParser:Parse(OrderInfo), JsonArray).
myOrder = OrderArray:GetJsonObject(2).
myOrder:Write(myLongchar, TRUE).
The following is the resulting myLongchar value:
 
{“OrderNum”: 83, “OrderDate”: “2010-09-20”}

Previous Next
© 2013 Progress Software Corporation and/or its subsidiaries or affiliates.