Home > Web Front-end > JS Tutorial > json data processing skills (fields with spaces, adding fields, sorting, etc.)_javascript skills

json data processing skills (fields with spaces, adding fields, sorting, etc.)_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:32:18
Original
1650 people have browsed it

1. The normal value of json data: json[i].fieldName

2. The field of json data has spaces: eval('json[' i ']["' field '"]')

3. Assignment of json data: eval('json[' i ']["' field '"]=' jsonFilter.length);

4. Add fields to json data: loop all data , just 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 of json data: var newObject = jQuery.extend(true, {}, oldObject); Please refer to: Copy of json object in jQuery (array and objects)

7. Adding and deleting json arrays, etc.: 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.push(item); This creates a json array with two fields id and value, and adds a record to the array.

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Backslash present in Json
From 1970-01-01 08:00:00
0
0
0
Get: Transfer JSON data
From 1970-01-01 08:00:00
0
0
0
mysql storage json error
From 1970-01-01 08:00:00
0
0
0
javascript - Problems with displaying json data
From 1970-01-01 08:00:00
0
0
0
Find matching integers in JSON.
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template