【问题标题】:How to get XML string within JSON field?如何在 JSON 字段中获取 XML 字符串?
【发布时间】:2013-12-17 13:02:47
【问题描述】:

我想通过 JSON 将结果输入到 jquery 数据表中。 该页面是用 JSP 编写的。

该表包含一个带有 XML 字符串的特殊字段:

{ 
  "sEcho": 1, 
  "iTotalRecords": "3800", 
  "iTotalDisplayRecords": "3800", 
  "aaData": [ [ "16.12.2013 14:14:55 GMT", 
                "Unknown", 
                "Unknown", 
                "", 
                "26414321279", 
                "ci1387203295280.36875276@czchols2138_te", 
                "<?xml version="1.0" encoding="UTF-8"?> <ExtendedEventContent> <Transport_Failure> <Error>Incomplete data received</Error> <Transport_Error>com.cyclonecommerce.tradingengine.transport.FileNotFoundException: 550 TEST.xml: The system cannot find the file specified. ; command=RETR TEST.xml</Transport_Error> </Transport_Failure> </ExtendedEventContent> ", 
                "" ] ,
               ...

数据表启动脚本:

<script>
  $(document).ready(function() {
    $('#failedDetails').dataTable( {
      "bStateSave": true,
  "bProcessing": true,
  "bServerSide": true,
      "sAjaxSource": "./inc_failed_details_json.jsp",
  "aLengthMenu": [[10, 50, 100, -1], [10, 50, 100, "All"]],
      "iDisplayLength": 10,
  "aaSorting": [[ 0, "asc" ]]
 } );

});

我当然收到错误:

...无法解析来自服务器的 JSON 数据。这是由 JSON 格式错误引起的。

数据是从 Oracle DB 收集的。 我尝试使用以下方式替换 XML 值:

(select replace(max(details), '"', '\"') from cyclone.messageevents where messageoid = m.oid) Details,
 "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <ExtendedEventContent> <Reason> <Event>Messaging.Message.Duplicate.Message</Event> </Reason> </ExtendedEventContent> "

但结果相同。

有没有人可以提供帮助?

【问题讨论】:

    标签: jquery xml json datatables


    【解决方案1】:

    您需要在您的XML field 中将" " 转换为' '

    我已经创建了 jsfiddle 到 DEMO

    var obj1 = {};
    obj1.data = "Name"
    obj1.xmlData = "<?xml version='1.0' encoding='UTF-8'?> <ExtendedEventContent> <Transport_Failure> <Error>Incomplete data received</Error> <Transport_Error>com.cyclonecommerce.tradingengine.transport.FileNotFoundException: 550 TEST.xml: The system cannot find the file specified. ; command=RETR TEST.xml</Transport_Error> </Transport_Failure> </ExtendedEventContent>"
    
    $(document).ready(function() { 
        $('.test').html(JSON.stringify(obj1));
    });
    

    【讨论】:

    • 谢谢帕特尔。很好的解决方案。即使我已经通过regexp_replace(to_char(wm_concat(rejectedreason)), '[[:cntrl:]]|\\') 解决了这个问题,同时从数据库收集数据我肯定会重用你的解决方案来解决另一个痛点:) 再次感谢 Rudo
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    • 1970-01-01
    • 2021-05-13
    • 1970-01-01
    • 2015-03-29
    • 2017-09-16
    相关资源
    最近更新 更多