Home > Web Front-end > JS Tutorial > body text

js method to convert key-value pair string to json string

亚连
Release: 2018-05-28 10:38:16
Original
2171 people have browsed it

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("&","\",") + "\"}";
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!