当前位置:网站首页>js 替换字符串中所有 “ 引号 —— 数据处理
js 替换字符串中所有 “ 引号 —— 数据处理
2022-07-30 05:46:00 【樂途途】
描述:
例如:我有组动态数据格式是"text":[“aaa”,“bbb”]
如何转化为"text":“[“aaa”,“bbb”]”
处理:
提示:注意数据类型转换处理:
处理代码:
let text=["aaa","bbb"]
// 1、JSON数组转化为JSON字符串
let str=JSON.stringify(text)
// 2、用字符串的replace方法进行对应的字符替换
// let rep=str.replace(/\"/g,'\\"').replace(/\[/g,'\"[').replace(/\]/g,'\]"');
let rep=str.replace(/\"/g,'\\"').replace('[','"[').replace(']',']"');
console.log('替换后数据:'+rep); // "[\"aaa\",\"bbb\"]"
注意:
提示:留意对 " 的替换处理:
例如:将 " 替换为 $"
let rep=str.replace(/\"/g,"$\"") // [$"aaa$",$"bbb$"]
如果有什么好的方法可以实现上述案例的转换效果,欢迎留言交流,让俺学习学习;要是哪里表述不对,也欢迎留言指正
边栏推荐
- 【Qingdao Station】High-level application of SWAT model and modeling of areas without data, uncertainty analysis and climate change, improvement of land use surface pollution impact model and case analy
- 用pop3收取gmail的邮件
- Map making of environmental impact assessment based on remote sensing interpretation and GIS technology (the latest guidelines)
- openssl1.1.1ARM双编译
- 昆仑通态屏幕制作(连载3)---基础篇(按钮串口发送)
- Kunlun State Screen Production (serialization 4) --- Basics (graphical setting and display, button lights)
- 高集成度 MCU 市场增大,如何加速 BLDC 领域落地应用
- 昆仑通态屏幕制作(连载1)---接触篇
- 闭包(你不知道的JS)
- influxDB运维记录
猜你喜欢

探究make_shared效率

“R语言+遥感”的水环境综合评价方法

QT每周技巧(3)~~~~~~~~~串口添加

UAV ecological environment monitoring, image processing and GIS data analysis

Rsync realizes folder or data synchronization between Win systems
![[Jiangsu University Automation Association stm32F103c8t6] Notes [Initial 32 MCU and EXTI External Interrupt Initialization Parameter Configuration]](/img/e5/87cf293ac3d0c613864e99a8fe9a47.png)
[Jiangsu University Automation Association stm32F103c8t6] Notes [Initial 32 MCU and EXTI External Interrupt Initialization Parameter Configuration]
Three working modes of CPU: real mode, protected mode, long mode

BLDC电机应用持续火爆,“网红神器”筋膜枪前景几何?

迪文串口屏幕制作(连载一)=====准备工作

使用Dva项目作Antd的Demo
随机推荐
昆仑通态屏幕制作(连载3)---基础篇(按钮串口发送)
Through the bit operations to convert the characters are case sensitive
基于全球模式比较计划CMIP6与区域气候-化学耦合模式 WRF-Chem 的未来大气污染变化模拟
ipconfig Command Guide
求职准备知识点
QT serialization 1: readyRead() function, the solution to incomplete data subcontracting
查看 word版本号
【速成MSP430f149】电赛期间学习MSP430f149笔记
Basic application of XMLBean
OpenLayers 初学者指南,源码测试可用
[Jiangsu University Self-Chemistry Association stm32F103c8t6] Notes [Introduction to 32 MCUs and Using TIM Output to Compare and Configure PWM]
Anaconda 安装低版本tensorflow
influxDB运维记录
基于MATLAB 2021b的机器学习、深度学习
“R语言+遥感”的水环境综合评价方法
openssl1.1.1ARM双编译
HSPF 模型应用
通过位运算进行字符大小写转换
闭包(你不知道的JS)
原创 Acegi 1.03 安全机制