JSON Learning JSON in JavaScript detailed instructions_json
1. Create an object using JSON in javascript
Js code
//Create an empty object
var JSONObject = {}
//Create a new object
var JSONObject = new Object()
/ /Create an object containing properties, where the name is a string and the age is an integer
var JSONObject = {
"name":"kevin",
"age":23
}
Similar to java, we can get the properties of an object through the dot (.) operator.
var JSONObject = {
"name":" kevin",
"age":24,
};
alert("JSONObject.name:" JSONObject.name);
alert("JSONObject.age:" JSONObject.age );
2. Use JSON to create array objects in javascript
Create a Student object, which contains two array objects, each array object , contains the properties of the Student object.
var student = {
// The first array object Class
"Class":[
"{
"name":"kevin",
"className":"java",
"age":23
],
/ /The second array object
"Score":[
" {
" name": "shower",
"score":100
},
{
" name":"zheng",
"score":100
" " }
" " ]
}
var i=0;
for(i=0; i
alert("student .Class[" i "].className===>" student.Class[i].className);
alert("student.Class[" i "].age===>" student.Class [i].age);
}
for(i=0;i
alert("student.Score[" i "].score===>" student.Score[i].score);
}
3. Use JSON to create messages in javascript
Copy code
//create a Student Object
var Student = {
"Math":[{
"name":"kevin",
"mark":70,
"age":23
},{
"name":"smart",
"mark":40,
"age":25
}
],
"Science":[{
"name":"kevin2",
"mark":70,
"age":23
},{
"name":"smart2",
"mark":40,
"age":25
}
]
}
//print array value
var i = 0;
var array = new Array();
for(i=0;i
array.push(Student.Math[i].mark);
array.push(Student.Math[i].age);
}
for(i=0;i
array.push(Student.Science[i].mark);
array.push(Student.Science[i].age);
}
alert("array==>" array);
//This method produce a JSON text from a JavaScript value.
//这个方法将一个JavaScript值转换为一个JSON字符串
alert("array.toJSONString()==>" array.toJSONString());
alert("String.parseJSON==>" array.toJSONString().parseJSON());
var data2 = array.toJSONString().parseJSON();
if(data2 instanceof Array){
alert("Array");
}
//表达式有浏览器兼容问题
//var cx = /[u0000u00adu0600-u0604u070fu17b4u17b5u200c-u200fu2028-u202fu2060-u206fufeffufff0-uffff]/g,
// escapable = /[\"x00-x1fx7f-x9fu00adu0600-u0604u070fu17b4u17b5u200c-u200fu2028-u202fu2060-u206fufeffufff0-uffff]/g,
//这个是修正后的
var cx = new RegExp('/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g'),
escapable = new RegExp('/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g'),

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Performance optimization methods for converting PHP arrays to JSON include: using JSON extensions and the json_encode() function; adding the JSON_UNESCAPED_UNICODE option to avoid character escaping; using buffers to improve loop encoding performance; caching JSON encoding results; and considering using a third-party JSON encoding library.

Annotations in the Jackson library control JSON serialization and deserialization: Serialization: @JsonIgnore: Ignore the property @JsonProperty: Specify the name @JsonGetter: Use the get method @JsonSetter: Use the set method Deserialization: @JsonIgnoreProperties: Ignore the property @ JsonProperty: Specify name @JsonCreator: Use constructor @JsonDeserialize: Custom logic

When editing text content in Word, you sometimes need to enter formula symbols. Some guys don’t know how to input the root number in Word, so Xiaomian asked me to share with my friends a tutorial on how to input the root number in Word. Hope it helps my friends. First, open the Word software on your computer, then open the file you want to edit, and move the cursor to the location where you need to insert the root sign, refer to the picture example below. 2. Select [Insert], and then select [Formula] in the symbol. As shown in the red circle in the picture below: 3. Then select [Insert New Formula] below. As shown in the red circle in the picture below: 4. Select [Radical Formula], and then select the appropriate root sign. As shown in the red circle in the picture below:

In-depth understanding of PHP: Implementation method of converting JSONUnicode to Chinese During development, we often encounter situations where we need to process JSON data, and Unicode encoding in JSON will cause us some problems in some scenarios, especially when Unicode needs to be converted When encoding is converted to Chinese characters. In PHP, there are some methods that can help us achieve this conversion process. A common method will be introduced below and specific code examples will be provided. First, let us first understand the Un in JSON

Title: Learn the main function in Go language from scratch. As a simple and efficient programming language, Go language is favored by developers. In the Go language, the main function is an entry function, and every Go program must contain the main function as the entry point of the program. This article will introduce how to learn the main function in Go language from scratch and provide specific code examples. 1. First, we need to install the Go language development environment. You can go to the official website (https://golang.org

PHP arrays can be converted to JSON strings through the json_encode() function (for example: $json=json_encode($array);), and conversely, the json_decode() function can be used to convert from JSON to arrays ($array=json_decode($json);) . Other tips include avoiding deep conversions, specifying custom options, and using third-party libraries.

JSON (JavaScriptObjectNotation) is a lightweight data exchange format commonly used for data exchange between web applications. When processing JSON data, we often encounter Unicode-encoded Chinese characters (such as "u4e2du6587") and need to convert them into readable Chinese characters. In PHP, we can achieve this conversion through some simple methods. Next, we will detail how to convert JSONUnico

PHP provides the following functions to process JSON data: Parse JSON data: Use json_decode() to convert a JSON string into a PHP array. Create JSON data: Use json_encode() to convert a PHP array or object into a JSON string. Get specific values of JSON data: Use PHP array functions to access specific values, such as key-value pairs or array elements.
