Home > Article > Web Front-end > js method to convert key-value pair string to json string
Below I will share with you a js method for converting key-value strings into json strings. It has a good reference value and I hope it will be helpful to everyone.
Key-value pair characters to be converted
var respDesc=“cardid=64157001&cardnum=1&sporder_id=PD12160428120635001&sporder_time=20160526101552”; var newstr = respDesc.replace("=",":\""); var stringObj= "{" +newstr.replace("&","\",") + "\"}";
The above is what I compiled for everyone Yes, I hope it will be helpful to everyone in the future.
Related articles:
vue uses axios to complete data interaction
Analyzing the source code example of Angular Component
Detailed example of storage method of original value and reference value in JS
# #
The above is the detailed content of js method to convert key-value pair string to json string. For more information, please follow other related articles on the PHP Chinese website!