Home Web Front-end JS Tutorial How to convert string to json string

How to convert string to json string

Apr 08, 2018 pm 05:28 PM
javascript json string

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

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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Performance optimization tips for converting PHP arrays to JSON Performance optimization tips for converting PHP arrays to JSON May 04, 2024 pm 06:15 PM

Performance optimization tips for converting PHP arrays to JSON

Detailed explanation of the method of converting int type to string in PHP Detailed explanation of the method of converting int type to string in PHP Mar 26, 2024 am 11:45 AM

Detailed explanation of the method of converting int type to string in PHP

How do annotations in the Jackson library control JSON serialization and deserialization? How do annotations in the Jackson library control JSON serialization and deserialization? May 06, 2024 pm 10:09 PM

How do annotations in the Jackson library control JSON serialization and deserialization?

How to repeat a string in python_python repeating string tutorial How to repeat a string in python_python repeating string tutorial Apr 02, 2024 pm 03:58 PM

How to repeat a string in python_python repeating string tutorial

PHP string manipulation: a practical way to effectively remove spaces PHP string manipulation: a practical way to effectively remove spaces Mar 24, 2024 am 11:45 AM

PHP string manipulation: a practical way to effectively remove spaces

PHP techniques for deleting the last two characters of a string PHP techniques for deleting the last two characters of a string Mar 23, 2024 pm 12:18 PM

PHP techniques for deleting the last two characters of a string

Go language tutorial: How to delete a string Go language tutorial: How to delete a string Mar 26, 2024 pm 01:42 PM

Go language tutorial: How to delete a string

How to convert string to float in PHP How to convert string to float in PHP Mar 27, 2024 pm 12:48 PM

How to convert string to float in PHP

See all articles