当前位置:网站首页>JSON in JS (launch object deep copy)
JSON in JS (launch object deep copy)
2022-07-28 05:16:00 【M78_ Domestic 007】
Full name :JavaScript Object Notation
JSON Is a string , A string format often used to transmit data over the network
Common string formats :
querystring Query string “name=karen&pwd=abc123&count=20"
template Template string `<div styLe="">666</div>`
JSON json character string ‘{"name " : " karen" , "its" : [ "heLLo" , "h5"]}’
JSON analysis
parse() Method Parse the string into objects
Anti parsing stringify() Parse the object into a string
Code display :
<script>
var re="JSON data "
var obj=JSON.parse(re)
console.log(re,obj)
//"JSON data " JSON data
var obj={name:"karen"}
console.log(obj)
//{name:"karen"}
var str=JSON.stringify(obj)
console.log(str)
//{"name":"karen"}
</script>Launch object deep copy 1( If there is no internal reference data or time regularity null Wait for data )
Ask for obj2 Object and the obj={name : "karen"} It looks the same , But they are not the same object , Can't write obj2={name : "karen"}
<script>
var obj={name:"karen"}
// Wrong way :
var obj2={}
obj2.name=obj.name
console.log(obj2,obj==obj2)//true
// It still points to the same memory space
// The right way :
var str=JSON.stringify(obj)//'{"name":"karen"}'
var obj2=JSON.parse(str)//{name:"karen"}
console.log(obj2,obj==obj2)//{name:"karen"} //false
</script>Object deep copy 2
<script>
function deepcopy(data){
if(typeof(data)=="object"){
if(data.constructor==Date){
return new Date(data.getTime())
}
else if(data==null){
return null
}
else if(data.constructor==RegExp){
return new RegExp(data)
}
else if(data.constructor==Array){
var newArray=new Array()
for(var i=0;i<data.length;i++){
var temp=data[i]
newArray.push(arguments.callee(temp))
}
return newArray
}
else{
var newobj=new data.constructor() //new Object()
// Object.keys()
for (var key in data) {
newobj[key]=arguments.callee(data[key])
}
return newobj
}
}
else{
return data
}
}
</script>边栏推荐
- Microservice failure mode and building elastic system
- Table image extraction based on traditional intersection method and Tesseract OCR
- What should testers know about login security?
- Array or object, date operation
- HDU 3592 World Exhibition (differential constraint)
- Classes and objects [medium]
- 在外包公司两年了,感觉快要废了
- Why is MD5 irreversible, but it may also be decrypted by MD5 free decryption website
- Jsonp single sign on permission verification
- Read the paper -- a CNN RNN framework for clip yield prediction
猜你喜欢

Message forwarding mechanism -- save your program from crashing

Data security is gradually implemented, and we must pay close attention to the source of leakage

How to send and receive reports through outlook in FastReport VCL?

数据安全逐步落地,必须紧盯泄露源头

mysql的日期与时间函数,varchar与date相互转换

阿里怎么用DDD来拆分微服务?

Array or object, date operation

Online sql to XML tool

RT based_ Distributed wireless temperature monitoring system of thread (I)
![[high CPU consumption] software_ reporter_ tool.exe](/img/3f/2c1ecff0a81ead0448e1215567ede7.png)
[high CPU consumption] software_ reporter_ tool.exe
随机推荐
MySQL(5)
HDU 2586 How far away ? (LCA multiplication method)
PC端-bug记录
Professor dongjunyu made a report on the academic activities of "Tongxin sticks to the study of war and epidemic"
塑料可以执行GB/T 2408 -燃烧性能的测定吗
阿里怎么用DDD来拆分微服务?
Look at the experience of n-year software testing summarized by people who came over the test
App test process and test points
如何在 FastReport VCL 中通过 Outlook 发送和接收报告?
Redux basic syntax
POJ 3728 the merchant (online query + double LCA)
【ARXIV2203】Efficient Long-Range Attention Network for Image Super-resolution
CPU and memory usage are too high. How to modify RTSP round robin detection parameters to reduce server consumption?
flink思维导图
Message forwarding mechanism -- save your program from crashing
Win10 machine learning environment construction pycharm, anaconda, pytorch
微服务故障模式与构建弹性系统
How to simulate common web application operations when using testcafe
Improving the readability of UI layer test with puppeter
After a year of unemployment, I learned to do cross-border e-commerce and earned 520000. Only then did I know that going to work really delayed making money!