js object ---》json

来源:互联网 发布:unknown网络 编辑:程序博客网 时间:2024/06/10 10:04
$(function(){debugger;var str1 = '{"name":"huangxiaojian","age":"23"}'//var selectType = $('.selectType option:selected').val();//alert(selectType );var str2 = [{ "value": "1", "text": "是" },{ "value": "0", "text": "否" }];   var json1 = JSON.parse(str1);//将json格式化成Objectvar json2 = JSON.stringify(str2);//将Object格式化成jsonalert(typeof(str1)+":"+typeof(str2));//转换前类型alert(typeof(json1)+":"+typeof(json2));//转换后类型alert(json1+":"+json2);})

0 0
原创粉丝点击