2017-02-15 64 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