29.10.2014, 21:16
(
Последний раз редактировалось KingHual; 30.10.2014 в 22:46.
)
Current version: v0.1.1
Last updated: 30/10/2014
Last updated: 30/10/2014
Why?
I decided to build this plugin as a fellow member of the SA-MP community was having issues with DJSON. DJSON is also outdated and does not conform to various JSON standards. It caches to disk, has a large memory footprint, and uses SQL for... JSON storage. It seemed wrong to me, so I decided to build my own plugin.
Features:
The plugin currently features a JSON parser for files located in your 'scriptfiles' directory. It's compliant to the JSON standards and can parse strings, numbers, booleans and arrays.
Documentation:
I'll be doing tutorials on the usage of this plugin, and a Wiki for all the functions. But for now, I'll just dump the functions with basic information about them here:
You can define a node delimiter by defining JSON_DEFAULT_DELIMITER to a char; Default delimiter is
pawn Код:
#define JSON_DEFAULT_DELIMITER '/'
pawn Код:
native JSONNode:json_parse_file(const file_path[])
Returns: A handle to the root node.
pawn Код:
native JSONNode:json_parse_string(const string[])
Returns: A handle to the root node.
pawn Код:
native json_close(JSONNode:node)
Returns: 1 on success, 0 on failure.
pawn Код:
native json_get_type(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER)
Returns: An integer representing the node's value type. See below for type definitions.
JSON type definitions:
pawn Код:
JSON_NULL
JSON_STRING
JSON_NUMBER
JSON_BOOL
JSON_ARRAY
JSON_NODE
pawn Код:
native JSONNode:json_get_node(JSONNode:node, const path[], const path_delim = JSON_DEFAULT_DELIMITER)
Returns: The node on success, 0 if the node doesn't exist.
pawn Код:
native bool:json_get_bool(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER)
Returns: The value of the specified path's key as a boolean.
pawn Код:
native json_get_int(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER)
Returns: The value of the specified path's key as an integer.
pawn Код:
native Float:json_get_float(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER)
Returns: The value of the specified path's key as a float.
pawn Код:
native json_get_string(JSONNode:node, dst[], const len = sizeof(dst), const path[] = '\0', const bool:packed = false, const path_delim = JSON_DEFAULT_DELIMITER)
Returns: 1.
pawn Код:
native json_get_name(JSONNode:node, dst[], const len = sizeof(dst), const bool:packed = false)
Returns: 1 if the node has a name (key) associated with it, 0 if it doesn't.
pawn Код:
native JSONArray:json_get_array(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER)
Returns: A JSON array type which is used for array functions.
pawn Код:
native json_array_count(JSONArray:array)
Returns: An integer representing the amount of elements 'array' contains.
pawn Код:
native JSONNode:json_array_at(JSONArray:array, const index)
Returns: The element as a JSON node.
Downloads:
Releases: GitHub
Source code: GitHub
Installation:
Download the release archive from the link provided above and place its contents into your server folder. Open your configuration file and add 'SAMPSON' ('SAMPSON.so' on Linux) to your 'plugins' line.
Building from source:
Download the source code from the link provided above.
On Windows, open the 'SAMPSON.sln' file in Visual Studio, select 'Release' build target and then build it.
On Linux, run 'make' in the 'src' folder. The built plugin should be found in the 'build' folder.
Credits:
- The SA-MP team - SA-MP, SA-MP plugin SDK
- Djole1337 - Testing support, Linux build support