Javascript chained string to JSON.

know how the string data.list.$items.gradeList.$items.desc is converted to

{
"data": {

"list": [
  {
    "gradeList": [
      {
        "desc": "9674"
      }
    ]
  }
]

}
}

this property is an array if the string is followed by $items.

May.31,2022

a.list1.$items.b.list2.$items.c.d to
{
a: {

list1: [
  {
    b:{
      list2:[
        {
          c:{
            d:'bug'
          }
        }
      ]
    }
  }
]

}
}
the next $items is the array

.
var str = 'data.list.$items.gradeList.$items.desc';
var item = '9674';
function exchange(str,item){
 str = str.split('.');
 var obj,flag = false;
 for(var i=str.length-1;i>=0;i--){
  obj={};
  str[i] == '$items'?(flag = true):
     (obj[str[i]]=flag?[item]:item,flag = false,item = obj);
 }
  return obj;
}
exchange(str,item);
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-1b33001-2b5d7.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-1b33001-2b5d7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?