Research on JSON format of lightweight Interactive Data

Source: Internet
Author: User

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

Why use JSON
When sending and receiving information in an asynchronous application, you can select plain text and XML as the data format. This phase of understanding Ajax discusses another useful data format, JavaScript Object Notation (JSON), and how to use it to move data and objects more easily in applications.
Simply put, JSON can convert a set of data represented in a javascript object to a string, and then it can be easily passed between functions, alternatively, the string is transmitted from the Web Client to the server in an asynchronous application. This string looks a bit odd (several examples will be seen later), but javascript can easily explain it, and JSON can represent a more complex structure than name/value pairs.

Features
Similar to XML
JSON is plain text
JSON is "self-descriptive" (human readable)
JSON has a hierarchical structure (Values exist in values)
JSON can be parsed using JavaScript
JSON data can be transmitted using Ajax

Differences from XML
No end tag
Shorter
Faster read/write speed
Ability to parse using the built-in JavaScript eval_r () method
Use Arrays
Do not use reserved words

Use JSON
Read JSON strings
Use eval_r () to process JSON strings

Json c ++ API is a good blog, complete.
Http://hi.baidu.com/jiangyangw3r/blog/item/bfedc1ce59b23e0c92457e14.html

An example of C ++ playing a 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 (OBJ );
// Input a student's JSON format 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;
}

 

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.