Posted By

Piotrek290 on 01/17/10


Tagged

javascript object array String tranform


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

nerdfiles


From JSON/Object/Array to STRING


 / Published in: JavaScript
 

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

Report this snippet  

You need to login to post a comment.