Thursday, 16 October 2014

json object parsing : get integer value of a JSON object in C programming using JSON C

By vm  |  06:42 No comments

The following program demonstrates this. the function json_parse accepts a json_object with one or more key:integer pairs.
#include <json/json.h>
#include <stdio.h>

void json_parse(json_object * jobj) {
 enum json_type type;
 json_object_object_foreach(jobj, key, val) {
 type = json_object_get_type(val);
 switch (type) {
 case json_type_int: printf("type: json_type_int, ");
 printf("value: %dn", json_object_get_int(val));
 break;
 }
 }
}
int main() {
 char * string = "{ "colors" : 7,
 "continents" : 7,
 "oceans" : 5
 }";
 printf ("JSON string: %sn", string);
 json_object * jobj = json_tokener_parse(string);
 json_parse(jobj);
}

Let’s compile the program. If you fail any compilation issues.. user gcc flag -std=c99 
Compile the program by using below command, here myprogram.c is your program name.
$ cc myprogram.c -ljson -std=c99

Author: vm

Hello, I am Author, decode to know more: In commodo magna nisl, ac porta turpis blandit quis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In commodo magna nisl, ac porta turpis blandit quis. Lorem ipsum dolor sit amet.

0 comments:

E-mail Newsletter

Sign up now to receive breaking news and to hear what's new with us.

Recent Articles

© 2014 VOIP4Learn. WP themonic converted by Bloggertheme9. Powered by Blogger.
TOP