JavaScript 从JSON / Object / Array到STRING

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript 从JSON / Object / Array到STRING相关的知识,希望对你有一定的参考价值。

$.json = function(a1){
	t=[];
	if(typeof a1=='string') return a1;
	if(typeof a1=='object') for(var x in a1)t.push(x+"="+encodeURI(a1[x]));
	if(a1.constructor==Object) for(var i=0;i<a1.length;i++) t.push(a1[i].name+"="+encodeURIComponent(a1[i].value));
	if(a1.constructor==Array) for(var i=0;i<a1.length;i++) t.push(a1[i].name+"="+encodeURIComponent(a1[i].value));
	
	return t.join("&");
};

以上是关于JavaScript 从JSON / Object / Array到STRING的主要内容,如果未能解决你的问题,请参考以下文章