js url 参数 转换成 json 对象数据

some=params&over=here => {"some":"params","over":"here"}

  

var params = getUrlVars('some=params&over=here');
console.log(params);

function getUrlVars(url) {
    var hash;
    var myJson = {};
    var hashes = url.slice(url.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        myJson[hash[0]] = hash[1];
    }
    return myJson;
}

  

posted @ 2018-09-17 20:38  @_追寻_@  阅读(5174)  评论(0编辑  收藏  举报