开发者

Jsp, Jquery and Json encoded characters issue

开发者 https://www.devze.com 2022-12-16 17:07 出处:网络
Working with JSON is quite new to me, yet I already like it. But i\'m facing an annoying issue. Here\'s how things work:

Working with JSON is quite new to me, yet I already like it. But i'm facing an annoying issue. Here's how things work: jquery makes an Ajax request for a specific url, this url is a STRUTS action, and, on success, returns a specific jsp this jsp includes JSON taglib (http://www.atg.com/taglibs/json) in order to render proper JSON formatting.

Shaping communications beetween client and server gives me this : alt text http://www.freeimagehosting.net/uploads/e4a91d6251.jpg

As you can see, http headers seem fine, yet, my JSON contains hex. characters, such as '

The problem is, I'm using part of the JSON answer to output html using Jquery; I'm facing this problem creating tooltips on the fly, each and every time the ajax request is made.

Maybe my javascript code isn't made to deal well with the JSON input , so heres a bit of my code to handle this JSON answer :

var toolTip = $("<span/>").addClass("tooltip").text(article.description).hide().appendTo(rowDescriptionArticle);

As you can see, I quite basically retrieve description for each article node, and insert it using text() into my span.

Any id开发者_JAVA百科ea what going wrong ?


There's nothing abnormal about JSON containing HTML entities — if that's part of a string that the browser is going to display, then it sounds fine.

Based on the jQuery snippet and JSON sample you posted, it looks like — in my non-jQuery-using opinion — you should be setting the html() rather than text() of the span, as your description field is already HTML-encoded.


Here's what my JSON looks like :

{"totalPanier":"0,00","articles":[{"id":"8a8b8d632481567f01248156fac90009","reference":"CART01","prixAffiche":"0,00","quantite":"0","libelle":"Carte CADEAUX Ã  montant variable","montantRemise":"","prixTotal":"00,00","visuel":"/documentsArticles/2009/14131/0005/209141310005_dim1.jpg","description":"Carte Cadeaux d&#039;une valeur de 15 Ã  150 euros."},{"id":"8a8b8d632481567f0124815706910010","reference":"CART80","prixAffiche":"80,00","quantite":"0","libelle":"Carte CADEAUX 80 Euros","montantRemise":"","prixTotal":"00,00","visuel":"/documentsArticles/2009/14131/0004/209141310004_dim1.jpg","description":"Carte Cadeaux d&#039;une valeur de 80 Euros."},{"id":"8a8b8d632481567f012481570578000f","reference":"CART50","prixAffiche":"50,00","quantite":"0","libelle":"Carte CADEAUX 50 Euros","montantRemise":"","prixTotal":"00,00","visuel":"/documentsArticles/2009/14131/0003/209141310003_dim1.jpg","description":"Carte Cadeaux d&#039;une valeur de 50 Euros."},{"id":"8a8b8d632481567f012481570549000e","reference":"CART30","prixAffiche":"30,00","quantite":"0","libelle":"Carte CADEAUX 30 Euros","montantRemise":"","prixTotal":"00,00","visuel":"/documentsArticles/2009/14131/0002/209141310002_dim1.jpg","description":"Carte Cadeaux d&#039;une valeur de 30 Euros."},{"id":"8a8b8d632481567f012481570364000d","reference":"CART15","prixAffiche":"15,00","quantite":"0","libelle":"Carte CADEAUX 15 Euros","montantRemise":"","prixTotal":"00,00","visuel":"/documentsArticles/2009/14131/0001/209141310001_dim1.jpg","description":"Carte Cadeaux d&#039;une valeur de 15 euros."}]}

Sorry for missing formating, yet I believe you'll be able to decode it a bit...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号