Research on lightweight interactive data JSON format

Source: Internet
Author: User

[W3cschool Tydef]
What is JSON?
JSON refers to JavaScript Object notation (JavaScript Notation)
JSON is a lightweight text data interchange Format
JSON Independent of Language *
JSON is self-descriptive and easier to understand
* JSON uses JAVASCRIPT syntax to describe data objects, but JSON is still independent of language and platform. The JSON parser and the JSON library support many different programming languages.
JSON syntax is a subset of JavaScript syntax.

Why do you use JSON
When sending and receiving information in an asynchronous application, you can choose to use plain text and XML as the data format. Mastering this phase of Ajax discusses another useful data format for JavaScript object Notation (JSON), and how to use it to move data and objects more easily in your application.
Simply put, JSON can convert a set of data represented in a JavaScript object into a string, which can then be easily passed between functions, or in an asynchronous application passing a string from a WEB client to a server-side program. The string looks a bit odd (see a couple of examples later), but JavaScript is easy to explain, and JSON can represent a more complex structure than name/value pairs.

Characteristics
Like XML
JSON is plain text
JSON has a "self-descriptive" (Human readable)
JSON has a hierarchy (values exist in values)
JSON can be parsed with JavaScript
JSON data can be transmitted using AJAX

Compared to the difference between XML
No end tag
Even shorter
Read and write faster
Ability to parse using the built-in JavaScript eval_r () method
Working with arrays
Do not use reserved words

Using JSON
Reading JSON strings
Processing JSON strings with Eval_r ()

JSON C + + API very good blog, all.
Http://hi.baidu.com/jiangyangw3r/blog/item/bfedc1ce59b23e0c92457e14.html

An example of a C + + hit JSON package
#include

Class Jsonguard
{

Public
Jsonguard (Json_object *obj): m_obj (obj) {}
~jsonguard () {
Json_object_put (m_obj);
}
Private
Json_object *m_obj;
};

void Testjson ()
{
cout << "Test json begin!" << Endl;
Json_object *obj = Json_object_new_object ();
Jsonguard Jsonguard (obj);
Hit a student in the JSON format for information
int id = 1;
Json_object_object_add (obj, "id", Json_object_new_int (ID));
String name ("Huangfengxiao");
Json_object_object_add (obj, "name", Json_object_new_string (Name.c_str ()));

Json_object *subobj = Json_object_new_object ();//subobj
String Mathadd ("A-404");
Json_object_object_add (subobj, "math", Json_object_new_string (Mathadd.c_str ()));
String Chineseadd ("A-404");
Json_object_object_add (Subobj, "Chineseadd", Json_object_new_string (Chineseadd.c_str ()));
Json_object_object_add (obj, "subjectaddr", subobj);

const char *jsdata = json_object_to_json_string (obj);
cout<<jsdata<<endl;
cout << "Test json end!" << Endl;
}

Research on lightweight interactive data JSON format

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.