【问题标题】:How to use html formatting I am getting from a Json Web Response?如何使用我从 Json Web 响应中获得的 html 格式?
【发布时间】:2013-04-29 13:49:50
【问题描述】:

我正在使用一个 Hotel Api 提供程序,它作为 Json 响应向我的应用程序发送一个包含字符串的 Json 节点。 在该字符串中,提供者使用了一些像这样的 html 格式:

"shortDescription": "<p><b>Location. </b> <br />The Edgewater - A Noble House Hotel is a business-friendly hotel located in central Seattle, close to Odyssey - The Maritime Discovery Center, Washington State Convention &"

当我尝试在我的 jspx 页面中的表格单元格中使用此字段时,我得到了没有格式的原始文本,并且带有所有段落和粗体标签。 有什么办法可以强制我的 jspx 页面显示这种格式? 谢谢。

【问题讨论】:

  • 请显示您用于将“shortDescription”分配给页面中的“表格单元格”的代码。
  • 你能展示你的代码吗?

标签: java json jsp jspx


【解决方案1】:

基本上你想用新内容替换旧内容。你可以使用jQuery.replaceWith

当您获得响应 JSON 时,例如,您可以将有问题的行替换为包含新数据的新行:

var rep = "<tr id='id-to-replace'><td>Description</td><td>" + responseJSON.description + "</td></tr>";
$('#id-to-replace').replaceWith(rep);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多