|
@@ -232,22 +232,18 @@ int json_parse(JsonParser* this, char* json) {
|
|
|
return JSON_OK;
|
|
|
}
|
|
|
|
|
|
-int get_type(JsonParser* this, char* key){
|
|
|
- //Recup index
|
|
|
- int index;
|
|
|
- if((index = search_index(this, key)) == JSON_ERROR){
|
|
|
- return JSON_ERROR;
|
|
|
- }
|
|
|
- return this->type[index];
|
|
|
-}
|
|
|
-
|
|
|
-char* get(JsonParser* this, char* key){
|
|
|
- //Recup index
|
|
|
- int index;
|
|
|
- if((index = search_index(this, key)) == JSON_ERROR){
|
|
|
+char* key_index(JsonParser* this, int index){
|
|
|
+ //Index incorrect
|
|
|
+ if(index < 0 || index >= this->elt){
|
|
|
return NULL;
|
|
|
}
|
|
|
- return get_index(this, index);
|
|
|
+ //Creation string d'accueil
|
|
|
+ char* val;
|
|
|
+ val = malloc(this->key_length[index] * sizeof(char));
|
|
|
+ //Copie valeur
|
|
|
+ strncpy(val, this->key[index], this->key_length[index]);
|
|
|
+ //Retour
|
|
|
+ return val;
|
|
|
}
|
|
|
|
|
|
char* get_index(JsonParser* this, int index){
|
|
@@ -264,6 +260,24 @@ char* get_index(JsonParser* this, int index){
|
|
|
return val;
|
|
|
}
|
|
|
|
|
|
+int get_type(JsonParser* this, char* key){
|
|
|
+ //Recup index
|
|
|
+ int index;
|
|
|
+ if((index = search_index(this, key)) == JSON_ERROR){
|
|
|
+ return JSON_ERROR;
|
|
|
+ }
|
|
|
+ return this->type[index];
|
|
|
+}
|
|
|
+
|
|
|
+char* get(JsonParser* this, char* key){
|
|
|
+ //Recup index
|
|
|
+ int index;
|
|
|
+ if((index = search_index(this, key)) == JSON_ERROR){
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+ return get_index(this, index);
|
|
|
+}
|
|
|
+
|
|
|
void clean_json_parser(JsonParser* this) {
|
|
|
free(this->key);
|
|
|
free(this->key_length);
|