I am trying to remove quotation marks from the responseText
property of a XMLHttpRequest
object.
My output is :
"[{"data":[[0,28]],"label":"Atyc-1"},{"data":[[0,13]],"label":"Atyc-10"},{"data":[[0,16]],"label":"Atyc-11"},{"data":[[0,17]],"label":"Atyc-2"},{"data":[[0,5]],"label":"Atyc-3"}]"
what I need is:
[{"data":[[0,28]],"label":"Atyc-1"},{"data":[[0,13]],"label":"Atyc-10"},{"data":[[0,16]],"label":"Atyc-11"},{"data":[[0,17]],"label":"Atyc-2"},{"data":[[0,5]],"label":"Atyc-3"}]
Try this:
JSON.parse(xhr.responseText);
Explanation:
It's a JSON response, which means the server is responding with JSON format. In order to use it properly in JavaScript, you need to parse the string as JSON using the JSON.parse()
function. That will convert the JSON object to the response you need.
responsetext.substring(1, responsetext.length - 1);
This will return the string with the first and last characters removed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With