js中实现json格式的转换

2021-07-14 02:05

阅读:514

标签:htm   his   ring   json格式   gif   log   highlight   pre   对象   

function person(id,name,age){
    this.id=id;
    this.name=name;
    this.age=age;  
}

var p=new person(1001,‘tom‘,27);

//转换为JSON格式     [{"id":1001,"name":"tom","age":27},{}...{}]
var jsonStr=JSON.stringify(p);


//将JSON格式解析为字符串
var strJson=JSON.parse(jsonStr);





//存储到localStoreage中
localStorage.person=jsonStr;


//从localStorage 中读取对象数据
var ls=localStorage.person;

  

js中实现json格式的转换

标签:htm   his   ring   json格式   gif   log   highlight   pre   对象   

原文地址:http://www.cnblogs.com/1020182600HENG/p/7077209.html

上一篇:css 初引

下一篇:html


评论


亲,登录后才可以留言!