简体   繁体   中英

how to get the json format from the encoded string

I am getting the following string in my request body:

params%5Bparam1%5D=543543&params%5Bparam2%5D=fdasghdfghdf&params%5Btest%5D=yes

How can I translate this to normal JSON?

This is the request body parsed to Lambda Proxy from API gateway.

If you want something quick and dirty in JavaScript (modified from this related answer )

 let params = "params%5Bparam1%5D=543543&params%5Bparam2%5D=fdasghdfghdf&params%5Btest%5D=yes"; let result = JSON.parse('{"' + decodeURIComponent(params) .replace(/"/g, '\\\\"') .replace(/&/g, '","') .replace(/params\\[/g, '') .replace(/\\]=/g, '=') .replace(/=/g, '":"') + '"}'); console.log(result);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM