Home  >  Article  >  Web Front-end  >  js method to convert key-value pair string to json string

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

亚连
亚连Original
2018-05-28 10:38:162186browse

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!

Statement:
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