簡體   English   中英

無法在 wordpress UI 中解析 json 字符串

[英]Unable to parse json string in wordpress UI

我正在嘗試修改 Wordpress 頁面 UI。 我寫了一個js函數:

<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>

當我調用這個函數時,我得到了 alert(userSettings) 的 [object Object]; 這意味着對象肯定在那里。 然后我得到真實的信息。 這意味着 window.JSON 正在工作。 在此之后,不會顯示任何警報消息。

我的主要目標是解析 json 並從 json 字符串中獲取 uid。

我還閱讀了此鏈接以獲得一些幫助https://www.learningjquery.com/2016/12/jquery-parsejson-vs-json-parse

userSettings已經是 JSON 格式。 只需使用userSettings.uid

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM