How to Create a JSON Data Type

Source: Internet
Author: User
Define Variables
. Local variable O, JSON

At this time, the O type is "null" and the constant value # JSON type. null

JSON Array
O. Add members (1)
O. Add member ("hello ")

Here, the o variable type is a JSON array. If the previous O type is also a "JSON array", two members will be added to the object o. If it is not a "JSON array", the previous content is cleared first.

JSON object
O. Set attributes ("attribute 1", 1)
O. Set attributes ("attribute 2", "hello ")

Here, the O type of the variable is a JSON object. If the type prior to o is also "JSON object", two attributes will be added for object o. If it is not a "JSON object", the previous content is cleared first.

Create a JSON data type from JSON text
O. parse (# JSON text)

JSON text is a string that conforms to the JSON syntax. The original content of variable O is cleared.

Generate JSON text
O. To text ()

Output The JSON content stored in variable O to text in JSON format.

Determine the type of a Variable
. Version 2
. JSON Library Supported

. Start to judge (O. Fetch type () = # JSON type. Object)
Output debugging text ("JSON object ")
. Judge (O. Fetch type () = # JSON type. array)
Output debugging text ("JSON array ")
. Judge (O. Fetch type () = # JSON type. Text)
Output debugging text ("text ")
. Default

To determine the JSON type of an object, you can use the O. Fetch type () to obtain it. Possible types include # JSON type. null, # JSON type. logic, # JSON type. floating Point, # JSON type. integer, # JSON type. text, # JSON type. object, # JSON type. array.

Get attribute or member Value
O. Retrieve common attributes ("attribute 1 ")
O. Retrieve common members (1)
O. Take attributes ("attribute 1 ")
O. Retrieve members (1)

If the attribute or member value is not of the # JSON type. object or the # JSON type. array, use the generic attribute () or the generic member () method. Otherwise, you can directly use the property () or the member ().

How to traverse JSON objects
O. Retrieve all attribute names ()

Sometimes the attribute names of some objects are unknown to us. You can obtain all attribute names of the JSON object by using all attribute names. Then, it traverses every attribute value of the JSON object.

How to traverse JSON Arrays
O. Number of members ()

Use the number of members () method to obtain the number of members, and then traverse them cyclically.

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.