JSON Library - modified from jsmn library
Diff: JSONObject.h
- Revision:
- 0:3c44784c513d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/JSONObject.h Sat Sep 30 09:11:57 2017 +0000 @@ -0,0 +1,48 @@ +#ifndef __JSON_OBJECT__ +#define __JSON_OBJECT__ + +/* Libraries */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "jsmn.h" + +/* Defines */ +#define NUM_OF_MAX_TOKEN 128 +#define NUM_OF_MAX_STRING_BUFFER 255 + +#ifdef __cplusplus + #define __boolType bool + #define __boolTrueValue true + #define __boolFalseValue false +#else + #define __boolType int + #define __boolTrueValue 1 + #define __boolFalseValue 0 +#endif /* __cplusplus */ + +/* Data types */ +typedef struct JSONObjectStruct +{ + const char *json_string; + jsmn_parser parser; + jsmntok_t tokens[NUM_OF_MAX_TOKEN]; + int tokens_counter; +} JSONObject; + +typedef enum { + OPERATION_FAIL = 0, + OPERATION_SUCCESS +} JSONObject_OperationResultCode; + +/* Methods */ +int __jsoneq(const char *json, jsmntok_t *tok, const char *s); +JSONObject *JSONObject_CreateObject(void); +JSONObject_OperationResultCode JSONObject_Parse(JSONObject *json_object, const char *json_string); +const char *JSONObject_GetOperationResultName(JSONObject_OperationResultCode code); +JSONObject_OperationResultCode JSONObject_GetString(JSONObject *json_object, const char *key, char **returnValue); +JSONObject_OperationResultCode JSONObject_GetFloat(JSONObject *json_object, const char *key, float *returnValue); +JSONObject_OperationResultCode JSONObject_GetInt(JSONObject *json_object, const char *key, int *returnValue); +JSONObject_OperationResultCode JSONObject_GetLong(JSONObject *json_object, const char *key, long *returnValue); +JSONObject_OperationResultCode JSONObject_GetBool(JSONObject *json_object, const char *key, __boolType *returnValue); +#endif /* __JSON_OBJECT__ */