2017-02-15 165 views
2

你好,我正在嘗試顯示一個html鏈接並通過json加載它,但我似乎無法得到這個工作我已經嘗試在下面,但它顯示爲文本而不是鏈接...用JSON顯示html鏈接

"test" : { 

"description": "A little test '<a href=\"https://www.google.com\">Visit Google<\/a>'" 

      } 

我自己也嘗試從a的結束標記去掉\但這似乎並沒有工作,任何想法的預先感謝您!

加載方法:利用圖書館3個JS

+1

你需要證明什麼是消費/使用此JSON或我們不能猜測爲什麼這不起作用...... JSON本身是數據,而不是代碼。 –

+0

你是指我如何加載它或哪個庫正在使用這些數據? –

+1

其中之一或兩者 - 無代碼的JSON只是文本,所以直到我們看到涉及的代碼時,不可能猜測可能發生了什麼。 –

回答

1

也許這是一個好主意,單獨的視圖和數據我已經提取的屬性

function() { 
     angular.module("testerMod").provider("language", function() { 
      "ngInject"; 
      this.path = "/assets/locale/", this.userLanguage = "en", this.$get = function(e) { 
       return ["$http", "$state", "$log", "$cookies", function(t, n, i, o) { 
        return function(a, s) { 
         var r, l, c; 
         return l = _.find(s.locales, { 
          code: a 
         }), null == l ? (r = _.find(s.locales, { 
          code: o["language"] 
         }), null != r ? a = r.code : (c = _.find(s.locales, { 
          code: e.userLanguage 
         }), a = null != c ? c.code : _.find(s.locales, { 
          "default": !0 
         }).code), void n.go("home", { 
          language: a 
         })) : t({ 
          method: "GET", 
          url: e.path + a + ".json" 
         }).then(function(e) { 
          return e.data 
         }, function(e) { 
          return i.error("Language Load Error") 
         }) 
        } 
       }] 
      }(this) 
     }) 
    } 

:鏈接源,鏈接文本,這樣的Json只會意味着傳輸數據和瀏覽器或應用程序將根據您的應用程序邏輯渲染視圖。

{ 
    "test":{ 
    "description": "A little test ", 
    "link_source":"https://www.google.com", 
    "link_text":"Visit Google" 
    } 
} 

爲您的版本工作,如果你想https://jsonformatter.curiousconcept.com/ 也有另一篇文章在這裏關於JSON序列化可以在此處檢查您的JSON的有效性http://www.popoloproject.com/appendices/json-patterns.html