I'm having a problem in converting an object
var obj={"Id":"1-AQC1Y1S","Root Order Item Id":"1-AQC1RSA","SC Long Description":"6.5" TXL/Qn/"};
In the above object, we have a value like 6.5" in a string. Please help me out here. Thanks in advance.
I'm having a problem in converting an object
var obj={"Id":"1-AQC1Y1S","Root Order Item Id":"1-AQC1RSA","SC Long Description":"6.5" TXL/Qn/"};
In the above object, we have a value like 6.5" in a string. Please help me out here. Thanks in advance.
Just escape it as follow: 6.5\"
Once again, that's not an array, is an object instead
var obj={"Id":"1-AQC1Y1S","Root Order Item Id":"1-AQC1RSA","SC Long Description":"6.5\" TXL/Qn/"};
console.log(obj["SC Long Description"])
Assuming that's the fixed structure, you can capture the the groups using a regexp, and make a replacement when the group "SC Long Description" is found:
var str = '{"Id":"1-AQC1Y1S","Root Order Item Id":"1-AQC1RSA","SC Long Description":"6.5" TXL/Qn/"}'
var found = false;
str = str.replace(/(".*?")(?!\})/g, function(match) {
if (found && match.endsWith('"')) return match.substring(0, match.length - 1) + '\\"';
found = found || match === '"SC Long Description"';
return match;
});
var obj = JSON.parse(str);
console.log(obj["SC Long Description"]);
You need to escape the double quotes, simple.
var array1 = {
"Id": "1-AQC1Y1S",
"Root Order Item Id": "1-AQC1RSA",
"SC Long Description": "6.5\" TXL/Qn/"
};
console.log(array1["SC Long Description"]);