Deserialize query string to JSON object

后端 未结 7 1221
感情败类
感情败类 2021-01-04 01:21

Tried to find how to make {foo:\"bar\"} from ?...&foo=bar&... but googled and got only to jQuery.params which does the opposit

7条回答
  •  一生所求
    2021-01-04 02:08

    I know this thread is a bit old - but this is what worked for me - hopefully it will help someone else too ..

    var _searchModel = yourquerystring.split("&");
    for (var x = 0; x < _searchModel.length; x++) {
      //break each set into key and value pair
      var _kv = _searchModel[x].split("=");
    
      //console.log(_kv);
    
      var _fieldID = _kv[0];
      var _fieldVal = _kv[1];
    }

提交回复
热议问题