javascript - The data format passed from the backend is like this, how to use it?
某草草
某草草 2017-06-30 09:56:44
0
4
811

Question: In the project, the data format passed from the backend is like this. How do I get the value in BYMONTH?

  INTERVAL=8;BYMONTH=9;BYMONTHDAY=17 
  

Thinking: A simple method I thought of is to parse it into JSON:

  var str = "INTERVAL=8;BYMONTH=9;BYMONTHDAY=17";
  var fiStr = '"' + str.replace(/=/g,'":"').replace(/;/g,'","');
var lastST = '{' + fiStr + '"}';
var Obj = JSON.parse(lastST);
console.log(Obj.BYMONTH)    

Question:
How should I handle this data format?

某草草
某草草

reply all(4)
刘奇
var res = {};
str.split(';').map(function(v){
    var i = v.split('=');
    res[i[0]]=i[1];
});
console.log(res['BYMONTH']);
某草草

"INTERVAL=8;BYMONTH=9;BYMONTHDAY=17".split(";")[2].split("=")[1]

黄舟
function getUrlParam(sUrl, sKey) {
    var result,Oparam = {};
    sUrl.replace(/[\;]?(\w+)=(\w+)/g,function($0,$1,$2){
       Oparam[$1]=$2;
    });
    sKey === void 0||sKey==='' ? result=Oparam : result=Oparam[sKey]||'';
    return result;
}
getUrlParam("INTERVAL=8;BYMONTH=9;BYMONTHDAY=17","BYMONTH")  //9
大家讲道理

What I’m more curious about is why the backend doesn’t directly return json format? It has to be processed on the front end.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template