How to convert an x-www-form-urlencoded string to JSON?

后端 未结 8 858
梦谈多话
梦谈多话 2020-12-05 02:34

Exampple of application/x-www-form-urlencoded string

CorrelationId=1&PickedNumbers%5B%5D=1&PickedNumbers%5B%5D=2&PickedNumbers%5B%5D=3&Picked         


        
8条回答
  •  旧时难觅i
    2020-12-05 03:14

    You can use qs if you're using node, or browserify.

    var qs = require('qs')
    var encodedString = "CorrelationId=1&PickedNumbers%5B%5D=1&PickedNumbers%5B%5D=2&PickedNumbers%5B%5D=3&PickedNumbers%5B%5D=4" 
    
    console.log(qs.parse(encodedString))
    // { CorrelationId: '1', PickedNumbers: [ '1', '2', '3', '4' ] }
    

提交回复
热议问题