This time I will show you how to convert a string to a json string, and what are the precautions for converting a string to a json string. The following is a practical case. Let’s take a look.
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("&","\",") + "\"}";
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to php Chinese Other related articles online!
Recommended reading:
JS+Canvas implements image preview compression and upload
How does Angular implement shared services and data in multiple components Communication
The above is the detailed content of How to convert string to json string. For more information, please follow other related articles on the PHP Chinese website!