I am trying to modify Wordpress page UI. I have written a js function:
<script type="text/javascript">function myfunction()
{
var userSettings = {"url":"\/","uid":"xyz","time":"1584212082","secure":"1"};
alert (userSettings);
if (window.JSON && window.JSON.parse)
{
alert ("true");
var auser = window.JSON.parse(userSettings);
if (auser == null)
{
alert ("Yes");
}
else
{ alert ("No") }
}
else
{
alert ("false");
}
}
</script>
when i call this function i get the [object Object] for alert(userSettings); That means object is surely there. Then i get true message. That means window.JSON is working. After this none of the alert message is displayed.
My main objective is to parse the json and get the uid from json string.
i also read this link for some help https://www.learningjquery.com/2016/12/jquery-parsejson-vs-json-parse