Skip to content

MySQL_GetJSONValueInt

imshooter edited this page Nov 3, 2026 · 1 revision

A value of a JSON cell as an integer.

A value that does not exist, is null, or is an object or an array leaves value as it was.

native bool:MySQL_GetJSONValueInt(row, const field[], const key[], &value);

Parameters

Parameter Description
row The row, from 0.
const field[] Name of the field.
const key[] Member of the top object or a JSON Pointer.
&value Variable for the integer.

Returns

  • true when the integer was written.
  • false when the value does not exist or is not a number, a bool or a string.

Remarks

A float is cut to a whole number, a boolean reads as 0 or 1 and a string holding a number is read as that number. A key the cell lacks leaves the variable as it was, so a value added in a later version of a script keeps its default for the rows saved before.

Example

forward OnItemRead(itemid);

public OnItemRead(itemid) {
    new
        amount = 1,
        Float:condition = 100.0,
        bool:locked
    ;

    MySQL_GetJSONValueInt(0, "attributes", "amount", amount);
    MySQL_GetJSONValueFloat(0, "attributes", "condition", condition);
    MySQL_GetJSONValueBool(0, "attributes", "locked", locked);

    printf("item %i: %i, %.1f%%, %s", itemid, amount, condition, locked ? ("locked") : ("open"));

    return 1;
}

Related

Clone this wiki locally