如何在JSON字段中获取XML字符串?

时间:2013-12-17 13:02:47

标签: jquery xml json datatables

我想通过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> ", 
                "" ] ,
               ...

datatables启动脚本:

<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> "
  

但结果相同。

是否存在可以提供帮助的人?

1 个答案:

答案 0 :(得分: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));
});