0

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

0

1 Answer 1

1

userSettings is already in JSON format. Just use userSettings.uid

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.