日本語 English

GetAryData

Overview

What Is GetAryData?

GetAryData is a SimpleJSON library function for extracting a specified element from a JSON array. JSON arrays can hold various data such as strings, numbers, Objects and arrays, and GetAryData gets the data at the position specified by DataIndex as-is.

JSON data received from Web APIs and JSON messages received from AWS IoT Core and the like sometimes contain multiple data items stored as an array. This function is used when handling such data on a PLC.

When it is used

GetAryData is used for purposes such as the following.

  • Parsing JSON arrays obtained from Web APIs
  • Processing JSON data received from AWS IoT Core on the PLC
  • Extracting Objects in a JSON array
  • Getting arrays inside an array in order
  • Receiving equipment information and sensor data in array form

Symbols

GetAryData

Extracting elements from a JSON array

func_getarydata
In-out
In
BYTE[*]
String starting with [
Input
DataIndex
UINT
Element number
Output
out
BYTE[65535]
Element value

About DataIndex

JSON arrays are numbered from 0.

DataIndexData obtained
0First element
1Second element
2Third element

Specifying a number that does not exist gives empty data.

Getting an Object

Even if an element of the JSON array is an Object, it can be obtained. The obtained data is a JSON string, so you can then use the Get function or similar to get data in the Object.

Getting an array inside an array

If an element of the JSON array is itself an array, it can also be obtained. By running GetAryData again on the obtained JSON array, nested arrays can be extracted in order.

Usage notes

  • The input data must be a JSON array starting with "[".
  • It cannot be used on JSON Objects.
  • Specifying a DataIndex that does not exist gives empty data.
  • Obtained Objects can be parsed with the Get function or similar.

Difference from the Get function

FunctionUse
GetGets from a JSON Object by key name
GetAryDataGets from a JSON array by element number

Execution example

In data (JSON)


Output when DataIndex=0 is specified

out

Output when DataIndex=1 is specified

out

FAQ

Can Objects inside an array be obtained?

Yes. The entire Object is returned as a JSON string.

What if DataIndex is out of range?

The result is empty data.

Can arrays inside an array be obtained?

Yes. Use GetAryData again after obtaining it.

Related pages

Comments