I have a list that i am trying to parse to a json object, ["Harry ", "Potter ", "Name ", "Batman"]
. I am using Django templates for this. I have parsed the list using simplejson.dumps()
.
I am trying to parse this in my javascript code.It is working fine until the line document.getElementById("demo").innerHTML = x;
in my code, it is printing ["Harry ", "Potter ", "Name ", "Batman"]
correctly.but JSON.parse()
is not working.The lines written after calling parse are not working. Can anyone tell me the problem with this code?
{%extends 'base.html'%}
{%block content%}
<p id="demo">hai {{y}} im</p>
<script>
var x = (("{{y}}").replace(/&(l|g|quo)t;/g, function(a,b){
return {
l : '<',
g : '>',
quo : '"'
}[b];
}));
x = x.replace(/u'/g, '\'');
x = x.replace(/'/g, '\"');
document.getElementById("demo").innerHTML = x;
p = JSON.parse( x );
document.getElementById("demo").innerHTML="Aray";
</script>
{%endblock%}
Thanks