C pointer principle (85)-json-glib analysis

Source: Internet
Author: User

JSON is JavaScript Object Natation. It is a lightweight data exchange format and is very suitable for server-to-JavaScript interaction. It is a language-independent text format and adopts a habit similar to the C language family. JSON is used to describe the data structure, which exists in the following form.

· Object: an object starts with "{" and exits. An object contains a series of non-sorted name/value pairs. Each name/value pair is partitioned by a comma.

· Name/value (collection): names and values are separated by ":". The general format is:

{Name: value}

A name is a string. A value can be a string, a value, an object, a Boolean value, a serial table, or a null value.

· The value has a serial table (Array): After one or more values are partitioned with ",", they are enclosed by "[", "]" to form such a list, shape:

[Collection, collection]

· String: a string of characters enclosed.

· Value: A combination of 0-9 numbers, which can be negative or decimal. You can also use "e" or "E" as an index.

· Boolean value: true or false.

All contents of the good AI Park blog is original, if reproduced please indicate the source http://blog.csdn.net/myhaspl/

WEB Development

JSON is widely used in WEB Application Development at the beginning. With the advent of Web2.0, JSON plays an important role in the WEB data transmission field. [Source request]

NoSQL Database

Compared with traditional relational databases, some NoSQL non-relational databases based on document storage use JSON as their data storage formats. Well-known products include MongoDB, CouchDB, and RavenDB.

The following is a json data that describes personnel information"

{

"FirstName": "John ",

"LastName": "Smith ",

"Male": true,

"Age": 25,

"Address ":

{

"StreetAddress": "21 2nd Street ",

"City": "New York ",

"State": "NY ",

"PostalCode": "10021"

},

"PhoneNumber ":

[

{

"Type": "home ",

"Number": "212 555-1234"

},

{

"Type": "fax ",

"Number": "646 555-4567"

}

]

}

JSON-GLib is a library that implements GLib and GObject for the full JSON analyzer. JSON-GLib is used to parse and generate a valid JSON data structure, using a dom api. JSON GLib also provides GObject integration, provides serialization and deserialization capabilities for GObject instances, from the JSON data type. JSON is the JavaScript Object Identifier, which can be used to represent objects and object hierarchies while retaining human readability.

GLib is the underlying core library of GTK + and GNOME engineering. It is a lightweight C library for comprehensive purposes, it provides the definition of common data structures in C language, related processing letters, interesting and practical macros, portable encapsulation, and some runtime capabilities, APIS such as event loops, threads, dynamic calls, and object systems. It can run on UNIX-like operating systems such as LINUX, HP-UNIX, WINDOWS, OS2 and BeOS.

The GObject object system provides a flexible, scalable, and easily mapped (to other languages) Object-oriented C language framework. Its essence can be summarized:

· A general type system is used to register any lightweight, inherited, single-node interface that can push and export any in-depth structure types, it takes care of the customization, initialization, and memory management of composite objects, class structures, maintains the parent-child relationship of objects, and handles dynamic implementations of these types. That is to say, these types of implementations are reset and uninstalled at runtime;

· An implementation set of a basic type, such as integer, enumeration, and structural;

· An example of implementation of the basic object type above the basic object system-the basic type of GObject;

· A signal system allows users to flexibly customize virtual or overloaded object methods, and can act as a highly effective notification mechanism;

· A Scalable parameter/variable system that supports all basic types that can be used to process object attributes or other parameterized types.

Open the JSON-GLIB Home Page:

Https://wiki.gnome.org/action/show/Projects/JsonGlib? Action = show & redirect = JsonGlib

Download version 0.99.2.

The following code uses the json-glib library to read the above personnel information:

# Include

# Include

# Include

Int

Main (int argc, char * argv [])

{

JsonParser * parser;

JsonNode * root;

GError * error;

If (argc <2)

{

G_print ("Usage: test \ N ");

Return EXIT_FAILURE;

}

G_type_init ();

Parser = json_parser_new ();

Error = NULL;

Json_parser_load_from_file (parser, argv [1], & error );

If (error)

{

G_print ("Unable to parse '% s': % s" \ n, argv [1], error-> message );

G_error_free (error );

G_object_unref (parser );

Return EXIT_FAILURE;

}

Root = json_parser_get_root (parser );

/* Manipulate the object tree and then exit */

G_object_unref (parser );

Return EXIT_SUCCESS;

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.