'Getting error in filter initialization in query builder
I am getting a string like this
"{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']},{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']}";
I can also put this in an object like this
obj : [ "{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']},{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']}";]
Problem is, filter of query builder can't read the value of this object because of those double quotes (") after and before square braces ([)
I just want to remove those double quotes from and object. So filter can read out object properly. So is there any method in javascript or c# to do this ?
My expected output is :
obj : [ {id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']},{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']}]
Solution 1:[1]
let str = "{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']},{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']}";
let obj = eval('(' + str + ')');
console.log(obj);
As a note - the string is weird, usually there are quotes around properties. See W3 Schools JSON Introduction
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
