feat: add array-create
This commit is contained in:
parent
8fc676b55c
commit
0c236825c3
|
@ -0,0 +1,25 @@
|
|||
#include <jansson.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
fprintf(stdout,"main() Started...\n");
|
||||
|
||||
json_t *array, *integer1, *integer2;
|
||||
size_t size;
|
||||
|
||||
array = json_array();
|
||||
|
||||
integer1 = json_integer(42);
|
||||
integer2 = json_integer(23);
|
||||
|
||||
json_array_append(array, integer1);
|
||||
json_array_append(array, integer2);
|
||||
|
||||
json_decref(integer1);
|
||||
json_decref(integer2);
|
||||
|
||||
size = json_array_size(array);
|
||||
|
||||
fprintf(stdout,"main() size: %ld\n", size);
|
||||
fprintf(stdout,"main() Done.\n");
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
# Docu
|
||||
#
|
||||
#$@ is the name of the file to be made
|
||||
#$? is the names of the changed dependents
|
||||
#$< the name of the related file that caused the action
|
||||
#$* the prefix shared by target and dependent files
|
||||
#
|
||||
# Others
|
||||
RM = /bin/rm -f
|
||||
#
|
||||
# Source, Executable, Includes, Library Defines
|
||||
EXE = main
|
||||
#
|
||||
# Compiler, Linker Defines
|
||||
CC = /usr/bin/gcc
|
||||
#
|
||||
all: main.o
|
||||
$(CC) main.c -L/usr/lib/x86_64-linux-gnu -ljansson -Wall -o $(EXE)
|
||||
#
|
||||
main.o:
|
||||
$(CC) -c main.c
|
||||
# Clean Up Objects, Exectuables, Dumps out of source directory
|
||||
clean:
|
||||
$(RM) *.o $(EXE) *~
|
|
@ -0,0 +1,17 @@
|
|||
* build
|
||||
|
||||
```
|
||||
make clean all
|
||||
```
|
||||
|
||||
* cleanup
|
||||
|
||||
```
|
||||
make clean
|
||||
```
|
||||
|
||||
* run
|
||||
|
||||
```
|
||||
./main
|
||||
```
|
|
@ -125,6 +125,7 @@ int main(int argc, char *argv[]) {
|
|||
if (!text)
|
||||
return 1;
|
||||
|
||||
/*decode the JSON text we got as a response*/
|
||||
root = json_loads(text, 0, &error);
|
||||
free(text);
|
||||
|
||||
|
@ -143,7 +144,10 @@ int main(int argc, char *argv[]) {
|
|||
json_t *data, *sha, *commit, *message;
|
||||
const char *message_text;
|
||||
|
||||
/*get i'th element of the 'root' array*/
|
||||
data = json_array_get(root, i);
|
||||
|
||||
/*Is 'data' a JSON object?*/
|
||||
if (!json_is_object(data)) {
|
||||
fprintf(stderr, "error: commit data %d is not an object\n", (int)(i + 1));
|
||||
json_decref(root);
|
||||
|
@ -170,11 +174,14 @@ int main(int argc, char *argv[]) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*extract C-style string from a JSON string*/
|
||||
message_text = json_string_value(message);
|
||||
printf("%.8s %.*s\n", json_string_value(sha), newline_offset(message_text),
|
||||
message_text);
|
||||
}
|
||||
|
||||
/*decrease the reference count*/
|
||||
/*this way the recource is released*/
|
||||
json_decref(root);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue