简体   繁体   English

解析 XML 时 JSON 中出现意外字符串

[英]Unexpected string in JSON while parsing XML

I am trying to read the clob which is basically XML from Oracle DB and populate in AngularJS UI Grid.我正在尝试从 Oracle 数据库中读取基本上是 XML 的 clob 并填充到 AngularJS UI 网格中。 I am doing the same with JSON and is working perfectly fine.我对 JSON 做同样的事情,并且工作得很好。

JSON response from backend JSON 来自后端的响应

{"events":{"ORDER_NO":"BBY01-100000709660","ORDER_HEADER_KEY":"2020040811522311790606  ","CREATETS":"2020-04-08 11:52:47","TMPLT_NM":"EOMS_0194                               ","EMAIL_XML":"<email CommunicationType=\"Email\" SourceSystem=\"OMS\" TemplatePageZone=\"\" brand=\"BESTBUY\" channel=\"BESTBUY\" emailAddr=\"test.tester@bestbuy.com\" template=\"EOMS_0178_TEST\">""    <name firstName=\"Test\" lastName=\"\" middleInitial=\"\"/>""    <order ATGID=\"ATG28268080246\" IsSuppressRequired=\"Y\" LoggedInFlag=\"Y\" LoyaltyID=\"0160140134\" OrderName=\"MSFTAllAccess\" PartyID=\"123456\" PriorityNumber=\"160140134\" customerPhoneNo=\"6515554321\" hasActivatedDevice=\"N\" orderDate=\"01/28/2020\" orderHeaderKey=\"2020012813423582265743\" orderIdATG=\"BBY01-1MT2010012802\" orderStatusLinkDisplayFlag=\"Y\" orderTotal=\"0.00\" orderTotalMinusCoupons=\"0.00\" partnerID=\"\" partnerOrderNo=\"MAV513281qweq1\" salesSource=\"BBYC\" shippingTotal=\"0.00\" taxTotal=\"0.00\">""        <creditCard cardType=\"\" number=\"\"/>""        <digitalCoupons digitalCouponTotal=\"0.00\"/>""        <lineItems>""            <lineItem CustPromiseDate=\"02/26/2020\" CustPromiseType=\"InHandDate\" availabilityMsg=\"\" beginEstArrivalDate=\"02/24/2020\" conditionVariableOne=\"\" conditionVariableTwo=\"\" description=\"Microsoft  Surface Pro 3  12  Intel Core i7  256GB  Silver\" endEstArrivalDate=\"02/26/2020\" expectedShipDays=\"\" format=\"\" giftPackaging=\"N\" inHandDate=\"02/26/2020\" itemID=\"\" itemShortDesc=\"Microsoft  Surface Pro 3  12  Intel Core i7  256GB  Silver\" lineItemProductTotal=\"0.00\" lineItemShippingCost=\"0.00\" merchClass=\"\" modelNo=\"1000186097\" orderLineKey=\"2020021911334791500160\" oversizeFlag=\"\" pickupDate=\"\" preOrder=\"\" primeLine=\"1\" productLine=\"6.403.635\" quantity=\"1\" releaseDate=\"\" reshipReasonCode=\"RESHIP_DAMAGED_ITEM\" shipDate=\"\" shippingMethod=\"\" signatureRequiredFlag=\"N\" sku=\"9248206\" status=\"\" subLine=\"1\" tax=\"0.00\" total=\"0.00\" unitPrice=\"0.00\" unitShippingCost=\"0.00\">""                <shippingAddr city=\"RICHFIELD\" line1=\"1000 W 78TH ST\" line2=\"\" state=\"MN\" zip=\"55423\">""                    <name firstName=\"Test\" lastName=\"Tester\" middleInitial=\"\"/>""                </shippingAddr>""                <allowance allowanceAmt=\"0.00\" reason=\"\"/>""                <return date=\"\" lineQty=\"\" lineTotal=\"0.00\" productCredit=\"0.00\" reason=\"\" restockingFee=\"0.00\" shippingCredit=\"0.00\" taxCredit=\"0.00\"/>""                <cancel backOrderExtendedXNumDays=\"\" reason=\"\"/>""                <ros actualDeliveryDate=\"\" pickupDate=\"\"/>""                <store storeName=\"\" storeNum=\"\"/>""                <psp plan=\"\"/>""                <carriers>""                    <carrier los=\"\" name=\"\" quantity=\"\" trackingNum=\"\"/>""                </carriers>""            </lineItem>""        </lineItems>""        <makeGood makeGoodFlag=\"N\"/>""    </order>""    <account atgProfileId=\"\" cirisID=\"\" info=\"\" password=\"\"/>""    <comments/>""</email>"}}

Whenever i am trying to read the values it is throwing exception每当我尝试读取值时,它都会抛出异常

Unexpected string in JSON at position 372 at JSON.parse ( <anonymous> ) JSON 中的意外字符串 position 372 在 JSON.parse ( <anonymous> )

Below is the AJAX response code:下面是 AJAX 响应代码:

$http.get(url).then(function(response) {
    if(response.data.events == null || response.data.events == undefined ||
            response.data.events == "undefined"){
        $("#loader1").hide();
        $scope.close = true;
        $scope.responseMessage = "";
        $scope.gridOptions1.data.length=0;
        $scope.errorMessage = "Order not found!!!!";
    }else{
        console.log("1");
        $("#loader1").hide();
        var responseNew = JSON.stringify(response.data.events);
        $scope.gridOptions1.data = responseNew;
        $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
        $scope.close = true;
        $scope.errorMessage = "";
        $scope.responseMessage = "Order details fetched successfully";
    }
}, function(response) {
    $("#loader1").hide();
    $scope.close = true;
    $scope.responseMessage = "";
    $scope.gridOptions.data.length=0;
    $scope.gridOptions1.data.length=0;
});

There's one double quote extra here:这里有一个额外的双引号:

Parse error on line 1:
...\"EOMS_0178_TEST\">""    <name firstName...
-----------------------^
Expecting 'EOF', '}', ':', ',', ']', got 'STRING'

use JSON.parse instead of JSON.stringify.使用 JSON.parse 而不是 JSON.stringify。 The response you're getting from back-end (the one you mentioned above) is already a stringified JSON, you have to parse it out to read the values.您从后端(上面提到的那个)得到的响应已经是一个字符串化的 JSON,您必须将其解析出来才能读取值。

The above issue waswhile storing the xml in DB.上述问题是在 DB 中存储 xml 时出现的。 since the new elements had spaces in between.因为新元素之间有空格。 it was considering that as a string and was getting appended with double quotes in JSON.它正在考虑将其作为一个字符串,并在 JSON 中附加双引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM