Thao Nguyen / JSONObject
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers JSONObject.h Source File

JSONObject.h

00001 #ifndef __JSON_OBJECT__
00002 #define __JSON_OBJECT__
00003 
00004 /* Libraries */
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 #include <string.h>
00008 #include "jsmn.h"
00009 
00010 /* Defines */
00011 #define NUM_OF_MAX_TOKEN 128
00012 #define NUM_OF_MAX_STRING_BUFFER 255
00013 
00014 #ifdef __cplusplus
00015     #define __boolType       bool
00016     #define __boolTrueValue  true
00017     #define __boolFalseValue false
00018 #else
00019     #define __boolType       int
00020     #define __boolTrueValue  1
00021     #define __boolFalseValue 0
00022 #endif /* __cplusplus */
00023 
00024 /* Data types */
00025 typedef struct JSONObjectStruct
00026 {
00027     const char *json_string;
00028     jsmn_parser parser;
00029     jsmntok_t tokens[NUM_OF_MAX_TOKEN];
00030     int tokens_counter;
00031 } JSONObject;
00032 
00033 typedef enum {
00034     OPERATION_FAIL = 0,
00035     OPERATION_SUCCESS
00036 } JSONObject_OperationResultCode;
00037 
00038 /* Methods */
00039 int __jsoneq(const char *json, jsmntok_t *tok, const char *s);
00040 JSONObject *JSONObject_CreateObject(void);
00041 JSONObject_OperationResultCode JSONObject_Parse(JSONObject *json_object, const char *json_string);
00042 const char *JSONObject_GetOperationResultName(JSONObject_OperationResultCode code);
00043 JSONObject_OperationResultCode JSONObject_GetString(JSONObject *json_object, const char *key, char **returnValue);
00044 JSONObject_OperationResultCode JSONObject_GetFloat(JSONObject *json_object, const char *key, float *returnValue);
00045 JSONObject_OperationResultCode JSONObject_GetInt(JSONObject *json_object, const char *key, int *returnValue);
00046 JSONObject_OperationResultCode JSONObject_GetLong(JSONObject *json_object, const char *key, long *returnValue);
00047 JSONObject_OperationResultCode JSONObject_GetBool(JSONObject *json_object, const char *key, __boolType *returnValue);
00048 #endif /* __JSON_OBJECT__ */