jsonDecode()

The function jsonDecode() decodes a JSON encoded string variable.

Synopsis

<any type> jsonDecode(string json);

Parameters

Parameter Description
json The string that is decoded. The variable was encoded by using the function jsonEncode().
Note:
The Byte-Order-Mark (BOM) is not processed but causes an error if it is contained in a string. See also the encoding parameters of the function fileToString().

Return Value

Decoded value

Description

JSON is a data exchange format and uses human-readable text for transmitting data objects. JSON builds two structures:

  • Name/value pairs. In different languages this is implemented as an object (object), a set (record), a structure (struct), a dictionary or a directory (dictionary), a hash table (hash table), a key list (keyed list) or as an associative array (associative array).

  • An ordered list of values. In most languages it is implemented as an array, a vector or a list.

It is largely used instead of XML. Furthermore, it is used for asynchronous browser/server communication (AJAX).

The JSON text format is independent of programming languages and is therefore ideally suited for data exchange.

Tip:
To detect decoding errors, use the function getLastError().
Note:

Since JSON only understands numeric and string data types, most of the WinCC OAdata types are converted to strings.

There are, however some exceptions:

  • atime -> object with elements:time, count, dpid
  • errClass -> object with elements: prio, type, id, text
  • langString -> object with one element per language
  • nullptr -> object with the JSON value of null

Assignment

Misc. functions

Availability

UI, CTRL