简体   繁体   English

Json 请求文本格式不正确

[英]Json request text not well formed

I'm using angularjs to make my first web application.我正在使用 angularjs 制作我的第一个 Web 应用程序。

I'm retreiving data from server as JSON object, and i'm trying to display in HTML page.我正在从服务器检索数据作为 JSON 对象,并且我试图在 HTML 页面中显示。 The json objet looks like : json 对象看起来像:

{
"title":"news1",
"description":"La fédération du <strong>Malawi<\/strong> n’a pas trop attendu pour remercier le sélectionneur <strong>Young Chimodzi<\/strong> après la défaite à domicile face au <strong>Zimbabwe.<\/strong>\ <br\/>\ <br\/>Le technicien local a été placé en congés jusqu’à la fin de son contrat qui expire à la fin de juillet prochain. La raison est simple, la défaite surprise face au Zimbabwe 1-2 lors de la première journée de la phase éliminatoire de la Coupe d’Afrique des nations Orange 2017.\ <br\/>\ <br\/>L’instance du pays a annoncé qu’un successeur à <strong>Young Chimodzi<\/strong> sera nommé le 1er aout prochain. Alors que l’intérim sera assuré par <strong>Ernest Mtawali.<\/strong>\" 

}

I'm using a simple ng-repeat to dislay text :我正在使用一个简单的 ng-repeat 来显示文本:

<div ng-rpeat="n in news">
<p>{{n.description}}</p>
</div>

I'm using a simple json request :我正在使用一个简单的 json 请求:

 $http.get("http://www.server/news", {headers:  {
        'Content-Type': 'application/json'
    }, })
        .success(function (response) {

            $scope.news = response;

        });

I tried to change the content type and to play with it but no changes我尝试更改内容类型并使用它但没有更改

the text is not well formed it's showing like that :文本格式不正确,它显示如下:

在此处输入图片说明

You want to render the html.您想呈现 html。 For that you need angular sanatize library.为此,您需要 angular sanatize 库。

Add angular-sanatize.js in your html, and in your module add dependency of ngSanatize.在您的 html 中添加 angular-sanatize.js,并在您的模块中添加 ngSanatize 的依赖项。

And update your html to并将您的 html 更新为

<p ng-bind-html="n.description"></p>

For details, refer to - https://docs.angularjs.org/api/ng/directive/ngBindHtml详情请参考 - https://docs.angularjs.org/api/ng/directive/ngBindHtml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM