From the course: Exploring C Libraries
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Reading JSON data
- [Narrator] To read a specific value from JSON data, you need to use the JSON-C library to create a JSON object variable. Next, you must know the element's name or key, as well as the type of data stored. This code searches the sample JSON data file, named at line seven, looking for the key name, "lastName", which is set at line eight. The file is opened at line 13, with a JSON object variable "jdata" holding the data. Line 21 creates a JSON object for the named key, which is saved in variable "objname", the third argument in the function. From this new object, the data type is determined by the JSON object get type function, found at line 29. Afterwards, a switch case structure is used to output the type of data found. I've already built and run the code, so let's see what it does. And the data type for last name, is a string. To show the variety of data types in the sample document, in this code, a while loop is found…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Understanding XML2m 23s
-
(Locked)
Testing the libxml2 installation3m 10s
-
(Locked)
Accessing XML data3m 26s
-
(Locked)
Generating XML data3m 57s
-
(Locked)
Working with JSON2m 39s
-
(Locked)
Testing the json-c installation3m 17s
-
(Locked)
Accessing JSON data3m 10s
-
(Locked)
Reading JSON data3m 46s
-
(Locked)
Creating JSON output3m 35s
-
-
-
-
-