aDataValue
📚 Related article is available here
Inherit from aDataElement
Append
Adds a value at end of an array and returns the data value to set.
Count
Returns the number of sub value.
CreateValue
Creates a data value in the document attachable with SetValue.
Find
Find(key: CString)
Gets a value from a map at the given key, returns undefined value when not found.
@param key key to map
FindAtPath
FindAtPath(path: CString)
This method allows to find an element according to a given path. The path has to start with a '/' and can be composed of key and/or index. @param path Path for the element to access to, using / as separator @returns A data value corresponding to the asked node. Undefined on errors
procedure myProcedure
uses aDataDocument, Doc, aStringFormat
var number : Int4
var data : aDataDocument
var myText : Text
var result : aDataValue
var error : aDataValue
new(data)
Write(myText, '{"result": [{"id": 0}, {"id": 1, "count":42}]}}')
if Doc.JSON.ParseText(data, myText)
if data.IsDefined
result = data.FindAtPath('result/1/count')
Write(result.ToCString)
;displays 42
endIf
else
error = data.GetError
myText := ''
if Doc.JSON.StringifyText(error, myText)
Write(myText)
endIf
endIf
endProc
Get
Get(index: Int4)
Gets a value from an array at the given index, returns undefined value when not found.
@param index index to access
GetClassname
Returns the className meta value of this value.
IsArray
True when the value is an array, otherwise false.
IsBoolean
True when the value is a boolean, otherwise false.
IsConstant
Checks if the value is writable (false) or read only (true).
IsDefined
True when the value is not undefined, otherwise false.
IsInteger
True when the value is an integer, otherwise false.
IsMap
True when the value is a map, otherwise false.
IsNull
True when the value is null, otherwise false.
IsNumber
True when the value is a number, otherwise false.
IsString
True when the value is a string, otherwise false.
IsSymbol
True when the value is a symbol, otherwise false.
IsUndefined
True when the value is undefined, otherwise false.
Key
Returns the key as a CString for a Map node, empty otherwise.
var doc: aDataDocument
var value : aDataValue
var myText: Text
new(doc)
Write(myText, '{"result":true, "count":42}')
if doc.Parse(myText)
foreach value in doc
WriteLn(value.Key) ;displays result
endFor
endIf
dispose(doc)
Map
Map(key: CString)
Provides a value at the given key, and creates it when not exists.
@param key key to map
NewIterator
Returns an iterator pointing to the first element in the current node. The current node has to be an Array or a Map. The foreach construct can be used to iterate.
var data: aDataDocument
var value : aDataValue
var myText: Text
new(data)
Write(myText, '{"result":true, "count":42}')
if data.Parse(myText)
foreach value in data
WriteLn(value.Key) ;displays result then count
WriteLn(value.toCstring)
WriteLn
endFor
endIf
myText:=''
Parse
Parse(json: Text)
Parses a text, constructing the data tree described by the text.
@param json The JSON text to parse
@returns True
var doc: aDataDocument
var myText: Text
new(doc)
Write(myText, '{"result":true, "count":42}')
if doc.Parse(myText)
if doc.IsDefined
;do stuff
endIf
endIf
Prepend
Adds a value at begin of an array and returns the data value to set.
SetArray
Sets the value to an empty array.
SetBool
SetBool(value: Boolean)
Sets the value to the given boolean.
@param value value to set
SetCString
SetCString(value: CString)
Sets the value to the given cstring.
@param value value to set
SetCString_
SetCString_(value: CString)
Deprecated, use SetCString instead
@param value value to set
SetChars
SetChars(value: tpChar)
Sets the value to the given terminated string.
@param value value to set
SetClassname
SetClassname(classname: CString)
Setter of the className meta value. @param classname value to assign
SetCopyOf
SetCopyOf(value: aDataValue)
Fills the value by duplicating the first level of properties or items.
@param value value to set
SetDifferenceOf
SetDifferenceOf(value: aDataValue, subtrahend: aDataValue)
Fills the value with the difference between minuend and subtrahend.
@param value value to set
SetInt
SetInt(value: Int8)
Sets the value to the given integer.
@param value value to set
SetMap
Sets the value to an empty map.
SetNull
Sets the value to null.
SetNum
SetNum(value: Num8)
Sets the value to the given number.
@param value value to set
SetText
SetText(value: Text)
Sets the value to the given text.
@param value
: value to set
value
is copied and can/should be cleared afterwards.
SetUndefined
Sets the value to undefined.
SetValue
SetValue(value: aDataValue)
Fills the value with the content of another.
@param value
: value to set
Stringify
Converts the current node to a string.
@param _Result the output from the conversion
ToBool
Converts a value a boolean, returns false by default.
ToCString
Converts a value a cstring, returns '' by default.
ToInt
Converts a value a integer, returns 0 by default.
ToNum
Converts a value a number, returns 0.0 by default.
ToText
Converts a value a text, returns '' by default.