Json data processing skills (fields with spaces and adding fields)

Source: Internet
Author: User

1. Normal Value of json data: json [I]. fieldName

2. json data fields contain spaces: eval ('json ['+ I +'] ["'+ field +'"] ')

3. json Data assignment: eval ('json ['+ I +'] ["'+ field +'"] = '+ jsonFilter. length );

4. Add fields to json data: loop all data and directly use json [I]. newField = defaultValue.

5. Sorting of json data: equivalent to sorting of arrays. json. sort (function (a, B) {return a [name]> B [name]? 1:-1 });

6. Copy json data: var newObject = jQuery. extend (true, {}, oldObject); see copying json objects (arrays and objects) in jQuery)

7. add and delete json Arrays: concat method | join method | pop method | push method | reverse Method | shift method | slice Method | sort method | splice method | toLocaleString method | toString method | unshift method | valueOf Method

8. Example of creating a json array: var jsonArr = []; var item = {id: 'id1', value: 'val1'}; jsonArr. in this way, a json array with two field IDs and values is created, and a record is added to the array.

 

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.