Releases: Southclaws/pawn-json
1.4.1
Fixes an issue where JSON_ArrayIterate
would skip index 0 and potentially cause out of bounds errors too.
This change requires the index
variable be assigned -1
before using JSON_ArrayIterate
.
Example:
LoadMotelHubs()
{
new Node:node, Node:motels;
JSON_ParseFile(MOTEL_DATA_FILE, node);
JSON_GetArray(node, "motels", motels);
new Node:motel, index = -1, data[MOTEL_DATA], motelid;
while(!JSON_ArrayIterate(motels, index, motel))
{
JSON_GetInt(motel, "motelid", motelid);
JSON_GetString(motel, "name", data[MotelName]);
JSON_GetFloat(motel, "x", data[MotelX]);
JSON_GetFloat(motel, "y", data[MotelY]);
JSON_GetFloat(motel, "z", data[MotelZ]);
JSON_GetInt(motel, "interior", data[MotelInterior]);
JSON_GetInt(motel, "world", data[MotelVirtualWorld]);
JSON_GetInt(motel, "fee", data[MotelFee]);
map_add_arr(MotelHubs, motelid, data);
}
}
1.4.0
Adds JSON_ArrayIterate
to easily iterate through a JSON array.
Adds JSON_CountNodes
to count how many active JSON nodes currently exist in memory.
JSON_ArrayIterate
example:
new Node:node, Node:textures;
JSON_Parse(string, node);
JSON_GetArray(node, "textures", textures);
new Node:texture, i, index, modelid, txd[128], txt[128], color;
while(!JSON_ArrayIterate(textures, i, texture))
{
JSON_GetInt(texture, "index", index);
JSON_GetInt(texture, "modelid", modelid);
JSON_GetString(texture, "txd", txd);
JSON_GetString(texture, "texture", txt);
JSON_GetInt(texture, "color", color);
SetDynamicObjectMaterial(objectid, index, modelid, txd, txt, color);
}
The function will automatically increment the current index and also garbage collect any previously used JSON node during iteration.
native JSON_ArrayIterate(Node:node, &index, &Node:output);
native JSON_CountNodes();
1.3.0
Adds a pretty
option to JSON_SaveFile
(Thanks @xunder-matth!!!)
Adds JSON_GetType
to get the data type of a key in a JSON node.
Adds JSON_Keys
to iterate through a JSON node and fetch its keys.
native JSON_SaveFile(const path[], Node:input, bool:pretty = false);
native JSON_NODE:JSON_GetType(Node:node, const key[]);
native JSON_Keys(Node:node, index, output[], len = sizeof(output));
1.2.0
1.1.0
Adds the following natives:
native JSON_ParseFile(const path[], &Node:output);
native JSON_SetArray(Node:node, const key[], Node:array);
native JSON_Remove(Node:node, const key[]);
native JSON_ArrayAppend(Node:node, const key[], Node:input);
native JSON_ArrayRemove(Node:node, const key[], Node:input);
native JSON_ArrayRemoveIndex(Node:node, const key[], index);
native JSON_ArrayClear(Node:node, const key[]);
1.0.0
Built using: Pycckue-Bnepeg/samp-rs#18 (comment)