I have an array that is encoded in php using json_encode
$params = array(1=>'something','2'=>'two');
When I encode it using json encode, it will encode it using double quotes, which is fine in itself, but I'm trying to embed it in an anchor tag, and double quotes will ruin the attributes. <a class="btn ajax" data-method="test" data-params="{"one":"something","2":"two"}" href="#">test ajax link</a>
obviously, the second double quote in the data-params attribute breaks the connection.
So, I did the conversion of the string to single quotes, but I need to convert it to double quotes in order to be able to parse in javascript;
var string = {'one':'something','2':'two'} ;
JSON.parse will fail on this line, I tried
var jsonString = dataParams.replace('\'', '"');
but it seems to only convert the first single quote, and then stop. Any ideas?
Brian source share