-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_parser.c
More file actions
45 lines (33 loc) · 918 Bytes
/
json_parser.c
File metadata and controls
45 lines (33 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <jansson.h>
#include <string.h>
#include <stdio.h>
#define SHORE_CLIENT_JSON_VERBOSE
#define SHORE_CLIENT_STRING_LENGTH 4096
void json_fixstring(char *jsonstr, int length){
int i;
int s=0;
for(i=0; i<length; i++){
if(jsonstr[i]=='{') s++;
if(jsonstr[i]=='}') s--;
if(s==0){
jsonstr[i+1]='\0';
break;
}
}
}
void json_getvalue(char *jsonstr, char deststr[], char *result){
json_error_t error;
json_t *root = json_loads(jsonstr, SHORE_CLIENT_STRING_LENGTH, &error );
if(!root){
#ifdef SHORE_CLIENT_JSON_VERBOSE
printf("json_getvalue: root == null\n");
#endif
}
json_t *jsonData = json_object_get(root, deststr);
const char *r = json_string_value( jsonData );
strcpy(result,r);
#ifdef SHORE_CLIENT_JSON_VERBOSE
printf("json_string_value: %s\n",result);
#endif
json_decref( root );
}