html页面之间传递json数据

原页面

var orderData = {
	            	"roomNum": roomNum,
	            	"orderDay" : orderDay,
	            	"orderTime": orderTime
	            };
	            var jsonStr = JSON.stringify(orderData);
	            window.location.href="meetingRoomOrder.html?orderData=" + jsonStr;

接收页面

 var dataJson;
        $(function(){
            var str=window.location.search;  //获取链接中传递的参数
            orderData = str.substring(str.indexOf("=")+1);//?orderData={"roomNum":"210","orderDay":"TODAY","orderTime":["10301100","11001140"]}
            console.log(orderData)
            var dataJson = $.parseJSON(orderData); 
            console.log(dataJson)
        }); 

在这里插入图片描述
看地址栏,没问题,但是解析json出错
html页面之间传递json数据_第1张图片
解决:

var dataJson;
        $(function(){
            var str = window.location.search;  //获取链接中传递的参数
            orderData = str.substring(str.indexOf("=")+1);//?orderData={"roomNum":"210","orderDay":"TODAY","orderTime":["10301100","11001140"]}
            var reg = new RegExp("%22","g");
            var dataJson = $.parseJSON(orderData.replace(reg,"\"")); 
            console.log(dataJson)
        }); 

html页面之间传递json数据_第2张图片

你可能感兴趣的:(js)