[INC] JSON

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1229
Gender:
United States of America

[INC] JSON

Post by Archive-Poster »

JSON for Pawn
by Exolent

Introduction
This is pretty much a useless include for 90% or more of you scripters.
I was bored one day and decided to write this up, but never got around to completing it as much as I wanted to or testing fully.
This include allows you to parse a JSON string into an object, read/set data from/to that object, create JSON objects, and encode a JSON object to string.
I didn't have much time to write up the documentation but it should be easy to understand.
This include will most likely only come in handy for sending/receiving data to/from a web server, such as a PHP script.

Include Information

Code: Select all

#define JSON_KEY_SIZE   512
#define JSON_STR_SIZE   512

enum JSON
{
	JSON_INVALID = 0,
	
	JSON_Cell,
	JSON_Float,
	JSON_String,
	JSON_Object
};

// Create functions
JSON:json_create(bool:is_array=false)
JSON:json_from_array(const any:array[], size, JSON:types[]={JSON_INVALID}, JSON:force_type=JSON_INVALID)
JSON:json_from_array2(Array:array, size=-1, {Array,JSON}:types, bool:force_type=false)

// Set functions
bool:json_set_cell(JSON:object, const key[], any:value, JSON:type=JSON_Cell)
bool:json_set_array(JSON:object, const key[], const any:array[], size, JSON:types[]={JSON_INVALID}, JSON:force_type=JSON_INVALID)
bool:json_set_array2(JSON:object, const key[], Array:array, size=-1, bool:json_set_string(JSON:object, const key[], const string[])

// Get functions
bool:json_get_cell(JSON:object, const key[], &any:value, &JSON:type=JSON_Cell)
bool:json_get_array(JSON:object, const key[], any:output[], size, JSON:types[])
bool:json_get_array2(JSON:object, const key[], &Array:output, &size=0, &Array:types)
bool:json_get_string(JSON:object, const key[], output[], len)
JSON:json_get_type(JSON:object, const key[])

// Delete function
bool:json_delete(JSON:object, const key[])

// String functions
JSON:json_decode(const string[], &pos=0, len=0)
json_encode(JSON:object, output[], len)
json_escape(const string[], output[], len)

// Destroy function
bool:json_destroy(&JSON:object)
Attachments
json.inc.zip
(3.66 KiB) Downloaded 4 times

Who is online

Users browsing this forum: No registered users and 2 guests