1+ #include <stdio.h>
2+ #include <string.h>
3+ int jumpChar (const char * string , int * index , char Char ) {
4+ while (string [* index ] == ' ' ) {
5+ index ++ ;
6+ }
7+ return * index ;
8+ }
9+ int jumpNULL (const char * string , int * index ) {
10+ while (string [* index ] == ' ' || string [* index ] == '\n' ) {
11+
12+ index ++ ;
13+ }
14+ return * index ;
15+ }
16+ int indexCharInString (const char * string , int length , const char target ) {
17+ int i ;
18+ for (i = 0 ; i < length ; i ++ ) {
19+ if (string [i ] == target ) {
20+ { return i ; }
21+ }
22+ }
23+ return -1 ;
24+ }
25+ int sliceString (const char * string , int index , int length ) { return 0 ; }
26+
27+ int indexStringInString (const char * string , int length , const char * target ) {
28+ int index = 0 ;
29+ index = indexCharInString (string + index , length - strlen (target ), target [0 ]);
30+ while (memcmp (string + index , target , strlen (target )) != 0 ) {
31+ if (index > length ) {
32+ return -1 ;
33+ } else {
34+ index ++ ;
35+ index =
36+ indexCharInString (string + index , length - strlen (target ), target [0 ]);
37+ }
38+ }
39+ return index ;
40+ }
41+
42+ int main () {
43+ char json [] = "{\"int1\":1,\"str1\":\"2\",\"double1\":3.14,\"bool1\":true,"
44+ "\"char1\":48,\"null1\":null,\"array1\":[\"string\",1,null,"
45+ "true,false,3.14],\"json1\":{\"id\":0,\"status\":200}}" ;
46+ struct json1 {
47+ int int1 ;
48+ char * str1 ;
49+ double double1 ;
50+ _Bool bool1 ;
51+ char char1 ;
52+ void * null1 ;
53+ void * * array1 ;
54+ struct json1 * next ;
55+ };
56+ int strindex = 0 ;
57+ jumpNULL (json , & strindex );
58+ if (json [strindex ] != '{' ) {
59+ printf ("json parse failed" );
60+ } else {
61+ strindex ++ ;
62+ jumpNULL (json , & strindex );
63+ if (json [strindex ] != '"' ) {
64+ { jumpNULL (json , & strindex ); }
65+ }
66+ if (json [strindex ] != '"' ) {
67+ printf ("json parse failed" );
68+ } else {
69+ }
70+ }
71+ }
0 commit comments