-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_object_create.cpp
More file actions
26 lines (21 loc) · 911 Bytes
/
Copy pathjson_object_create.cpp
File metadata and controls
26 lines (21 loc) · 911 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
/** Originally created for testing purpose. Made by Sombaran Gupta.
* For any further query email me @ guptasombaran@yahoo.com
* Created for Linux environment
* @Brief: JSON-C library used to convert json string into object
* prints value to each key
* @return
*/
#include <iostream>
#include <json-c/json.h>
int main(void) {
const char *rec_msg = "{ \"fruit\": \"Apple\", \"size\": \"Large\", \"color\": \"Red\" }";
json_object * obj = json_tokener_parse(rec_msg);
std::cout << json_object_get_string(obj) << std::endl;
std::cout << json_object_get_string(json_object_object_get(obj,"fruit")) << std::endl;
std::cout << json_object_get_string(json_object_object_get(obj,"size")) << std::endl;
std::cout << json_object_get_string(json_object_object_get(obj,"color")) << std::endl;
std::cout << json_object_get_string(obj) << std::endl;
/* Free the JSON pointer */
json_object_put(obj);
return(0);
}