JSON對(duì)象數(shù)組
[{
"ulog_id":5,
"ulog_time":2015,
"user_name":"ceshi123"
},{
"ulog_id":4,
"ulog_time":2018,
"user_name":"ceshi123"
},{
"ulog_id":3,
"ulog_time":2017,
"user_name":"ceshi123"
},{
"ulog_id":2,
"ulog_time":2015,
"user_name":"ceshi123"
},{
"ulog_id":1,
"ulog_time":2015,
"user_name":"ceshi123"
}]
對(duì)象:
const o1 = { a: 1 };
const o2 = { b: 2 };
const o3 = { c: 3 };
JSON字符串:
var str1 = '{ "name": "cxh", "sex": "man" }';
JSON對(duì)象:
var str2 = { "name": "cxh", "sex": "man" };
1.eval()函數(shù):Json字符串轉(zhuǎn)對(duì)象
該方法只接受原始字符串作為參數(shù)惊橱,如果 string 參數(shù)不是原始字符串榄鉴,那么該方法將不作任何改變地返回引颈。因此請(qǐng)不要為 eval() 函數(shù)傳遞 String 對(duì)象來(lái)作為參數(shù)
json轉(zhuǎn)對(duì)象在取出對(duì)象數(shù)組中某個(gè)對(duì)象的value
2.Object.assign()的使用:http://www.reibang.com/p/f9ec860ecd81
2.map()函數(shù):根據(jù)條件遍歷返回出一個(gè)新的數(shù)組
4.數(shù)組:使用indexof()函數(shù)遍歷比較數(shù)組中的數(shù)有沒(méi)有‘2’若有輸出-1否則輸出0
5.json:根據(jù)指定條件取出json中指定的數(shù)據(jù)(filter()函數(shù))
6.JSON.parse()函數(shù):JSON字符串轉(zhuǎn)對(duì)象
var jsonStr = '{"key":"value"}';
var str1 = '{ "name": "cxh", "sex": "man" }';
console.log(JSON.parse(jsonStr));
結(jié)果:{key: "value"}
這種格式會(huì)報(bào)錯(cuò):var jsonStr1 = '{key:"value"}';
7.eval()函數(shù):JSON字符串轉(zhuǎn)對(duì)象
var jsonStr = '{"key":"value"}';
var jsonStr1 = '{key:"value"}';
console.log(eval('(' + jsonStr + ')')); // 結(jié)果:{key: "value"}
console.log(eval('(' + jsonStr1 + ')'));// 結(jié)果:{key: "value"}
8.數(shù)組轉(zhuǎn)字符串
var arr = [1,2,3,4,'巴德','merge'];
var str = arr.join(',');
console.log(str); // 1,2,3,4,巴德,merge
9.字符串轉(zhuǎn)數(shù)組
var str = '1,2,3,4,巴德,merge';
var arr = str.split(',');
console.log(arr); // ["1", "2", "3", "4", "巴德", "merge"] 數(shù)組
console.log(arr[4]); // 巴德
10.字符串轉(zhuǎn)數(shù)組沦童,數(shù)組轉(zhuǎn)數(shù)組格式化,數(shù)組格式化轉(zhuǎn)數(shù)組
var str = '1,2,3,4,巴德,merge';
var arr = str.split(',');
var strify = JSON.stringify(arr);
console.log(arr); // ["1", "2", "3", "4", "巴德", "merge"] 數(shù)組
console.log(arr[4]); // 巴德
console.log(strify); // ["1", "2", "3", "4", "巴德", "merge"] 字符串?dāng)?shù)組
var arrParse = JSON.parse(strify);
console.log(arrParse); // ["1", "2", "3", "4", "巴德", "merge"] 數(shù)組
11.JavaScript split() 方法
var str="How are you doing today?"