解析jQuery中

问题描述:

新的生产线最近,我问和回答了this question和它停止字符串文字错误的问题,但是它现在引起了另一个问题解析jQuery中

$(document).ready(function() 
{ 

    $("#message-list .message").click(function() 
    { 
     var msg_id = 1; 
     msg_id = $(this).attr('id').split('-')[1]; 
     $.ajax({ 
      type: "GET", 
      url: "get_message.php", 
      data: "id=" + msg_id, 
      success: function(msg){ 

       var converter = new Attacklab.showdown.converter(); 
       json = eval("("+ msg +")"); 
       var copy = converter.makeHtml(json.copy); 

       $("#message-details .subject").html(json.title); 
       $("#message-details .importance").html(json.importance); 
       $("#message-details .date").html(json.date); 
       $("#message-details .message").html(copy); 


      } 
     }); 
    }); 


}); 

这是jQuery函数的字符串解析成(json.copy确切地说是)并且是问题发生的地方。在我之前的问题中创建json字符串时,我们删除了\ r,因为它们没有被解析出来,并且\ n用\ n转义。但是现在我在屏幕上出现了打印新行的问题,并且需要使用此功能中的一种方法来解压缩它们,而不会再次导致未终止的字符串文字错误。

>_<

编辑:

消息:

所有人\ n \ n \ n \ n顾问\ n \ n \ n \ n在\ n \ n新城

即将进入的json字符串是:

{“title”:“再次测试”,“复制”:“全部\ n \ n \ n \ n \ n \ n助理\ n \ n \ n \ n \ n \ n \ n \ n \ n \ nnewtown”, “重要性”:“现在阅读”,“日期”:“2009-09-22 13:12:22”}

+0

猜我不理解:)你可以张贴味精的样子。 – Greg 2009-09-24 08:49:37

+0

消息 所有\ n \ n \ n \ n顾问\ n \ n \ n \ n在\ n \ n newtown json字符串表示进入:{“title”:“再次测试”,“复制” : “所有的\\ \\ññ\ n \\ \\ññ\ nadvisers \\ \\ññ\ n \\ \\ññ\ NAT \\ \\ññ\ nnewtown”, “重要”:”读现在“,”日期“:”2009-09-22 13:12:22“} – 2009-09-24 08:51:45

这是一个快速而肮脏的黑客攻击,但它也会很快:你只需将“\n”替换为“<br />”?

+0

这很好,可能是一个好主意大声笑...我会给它去 – 2009-09-24 09:17:37

+0

工作正常..谢谢! – 2009-09-24 11:55:54