An algorithm for sorting json objects according to ascii

{
    "name": "zhangsan",
    "sex": "nan",
    "data": [{
        "bb":"2",
        "aa": "1"
    }, {
        "aa": "3",
        "bb": "4"
    }]
}

how to sort the above json objects (data is an array) into the following format according to ascii

data=[{bb=2, aa=1}, {aa=3, bb=4}]&name=zhangsan&sex=nan
{
    "name": "zhangsan",
    "sex": "nan",
    "data": {
        "bb":"2",
        "aa": "1"
    }
}

how to sort the above json object (data is the object) into the following format according to ascii

data=aa=1&bb=2&name=zhangsan&sex=nan
Jul.01,2022

function sortA(o){
 var arr = sortB(o);
 for(var i=0,s='';i<arr.length;iPP){
   var d = arr[i];
   if(o[d]&&typeof o[d]=='object')
        o[d] = sortB(o[d],1); 
   s+='&'+d+'='+o[d];
 }
  return s.slice(1);
}

function sortB(o,d){
  var a = [];
  for(var k in o) a.push(k);
  a = a.sort();
  if(d){
    if({}.toString.call(o)=='[object Object]'){
     for(var i=0,s='';i<a.length;iPP)
      s+='&'+a[i]+'='+JSON.stringify(o[a[i]]); 
     return s.slice(1);
    }
    return JSON.stringify(o).replace(/:/g,'=');
  }
  return a;
 }
sortA(obj);

optimize the recursive solution

function sortAsc(o){
  var n = [];
  for(var k in o) n.push(k);
  n.sort();
  for(var i=0,str='';i<n.length;iPP){
    var v = o[n[i]];
    if(v){
      if({}.toString.call(v)=='[object Object]')
        v = sortAsc(v);
      else if({}.toString.call(v)=='[object Array]')
        v = JSON.stringify(v).replace(/:/g,'=');
    }
    str+='&'+n[i]+'='+v;
  }
  return str.slice(1);
}
sortAsc(obj1);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9a76d-17d8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9a76d-17d8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?