当前位置:网站首页>Two step processing of string regular matching to get JSON list
Two step processing of string regular matching to get JSON list
2022-06-26 05:10:00 【Light grey grey】
Let's talk about why we should do this
I met a poisonous problem these days ,elementplus Of table The table does not need a key value pair json Data list to display data .
The back end of a small project I wrote is go Language , The original meaning is that the back-end gets all the data from the database , Handle it on the back end : Package all the data into one with all json List of format data .
Then pass this list to the front end , Just assign the list directly . result go The list of languages is not like python The list of is actually there ,go The list of languages is the actual linked list , My front end can't get what I want json Data list .
So I thought of the back-end with all json The data string is passed to the front end , From the front end js Processing strings , Give me what I want json list .
Another regular expression testing tool is recommended : Regular expression online test | Rookie tools (runoob.com)
The next step is a simple one :
Get the back-end json data
// Get the back-end json data
var str = response['data']
Regular matches everything that includes braces , Returns an array
// Regular matches everything that includes braces , Returns an array
str = str.match(/{[^}{]*?}/g)
eval() Definition :eval() Function to evaluate a string , And execute the JavaScript Code .
because JSON Grammar is JavaScript A subset of grammar ,JavaScript function eval() Can be used for JSON The text is converted to JavaScript object
Now the list is still in string form json, Traversing the array converts the string to json
// But now the list is still in string form json, Traversing the array converts the string to json
for(var i=0;i<str.length;i++){
//eval() Definition :eval() Function to evaluate a string , And execute the JavaScript Code .
// because JSON Grammar is JavaScript A subset of grammar ,JavaScript function eval() Can be used for JSON The text is converted to JavaScript object
str[i] = eval ("(" + str[i] + ")")
// Console check data
console.log(str[i])
}边栏推荐
- UWB ultra high precision positioning system architecture
- Technical past: tcp/ip protocol that has changed the world (precious pictures, caution for mobile phones)
- 86.(cesium篇)cesium叠加面接收阴影效果(gltf模型)
- 【Unity3D】人机交互Input
- 微服务之间的Token传递之一@Feign的token传递
- Thoughts triggered by the fact that app applications are installed on mobile phones and do not display icons
- Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing
- pycharm 导包错误没有警告
- Generalized linear model (logistic regression, Poisson regression)
- Zhongshanshan: engineers after being blasted will take off | ONEFLOW u
猜你喜欢

Tp5.0框架 PDO连接mysql 报错:Too many connections 解决方法

Use fill and fill in Matplotlib_ Between fill the blank area between functions

Pycharm package import error without warning

钟珊珊:被爆锤后的工程师会起飞|OneFlow U

Yolov5 super parameter setting and data enhancement analysis

ECCV 2020 double champion team, take you to conquer target detection on the 7th
![C# 40. byte[]与16进制string互转](/img/3e/1b8b4e522b28eea4faca26b276a27b.png)
C# 40. byte[]与16进制string互转

Tensorflow and deep learning day 3

Transport layer TCP protocol and UDP protocol

pycharm 导包错误没有警告
随机推荐
Sklearn Library -- linear regression model
PHP one sentence Trojan horse
UWB ultra high precision positioning system architecture
Day3 data type and Operator jobs
Sentimentin tensorflow_ analysis_ cell
超高精度定位系统中的UWB是什么
cartographer_optimization_problem_2d
Computer Vision Tools Chain
Resample
[geek] product manager training camp
Protocol selection of mobile IM system: UDP or TCP?
[IDE(ImageBed)]Picgo+Typora+aliyunOSS部署博客图床(2022.6)
[ide (imagebed)]picgo+typora+aliyunoss deployment blog Gallery (2022.6)
zencart新建的URL怎么重写伪静态
Create a binary response variable using the cut sub box operation
RESNET practice in tensorflow
C# 40. byte[]与16进制string互转
A company crawling out of its grave
递归遍历目录结构和树状展现
Generalized linear model (logistic regression, Poisson regression)