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

Reading JSON data - C Tutorial

From the course: Exploring C Libraries

Start my 1-month free trial

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…

Contents