mirror of
https://github.com/NohamR/knowledge-kit.git
synced 2026-05-25 04:17:17 +00:00
docs: 批量博文
This commit is contained in:
28
Chapter2 - Web FrontEnd/2.8.md
Normal file
28
Chapter2 - Web FrontEnd/2.8.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# JSON的一些骚操作
|
||||
|
||||
* 将json转换为对象JSON.parse\(\)函数的第二个参数用来转换解析出的属性
|
||||
|
||||
```
|
||||
JSON.parse('{"name":"lbp","age":"20"}',function(key,value){
|
||||
if(key == "name"){
|
||||
return value + "同学";
|
||||
}
|
||||
return value;
|
||||
});
|
||||
```
|
||||
|
||||
* 将对象转换为json,JSON.stringify\(\)函数的第二个参数用来筛选对象的键值
|
||||
|
||||
```
|
||||
var student = {"name":"小米","age":22,"height":177,"skills":["js","oc"]};
|
||||
function convert(key,value){
|
||||
if (typeof value === "string") {
|
||||
return value.toString().toUpperCase();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
JSON.stringify(student,convert,' ');
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user