gpt4 book ai didi

java - 使用Java解析XML转换为Json

转载 作者:太空宇宙 更新时间:2023-11-04 10:47:34 24 4
gpt4 key购买 nike

下面是 JSON,我需要解析其中的值:

"primaryInvolvedParty": 
{
}

响应是 XML,因此它被转换为 JSON,以便我可以轻松解析它。

使用以下方法将 XML 转换为 JSON:

String messageBody = actualResult.get("StatusMessage");
JSONObject xmlconvertedjson=XML.toJSONObject(messageBody);
JsonElement jelement = new
JsonParser().parse(xmlconvertedjson.toString());

但我正在寻找可以获取给定属性的键值的通用函数,例如:customerScore.scoreResult= Accept,请帮忙,因为我是放心解析的新手。

JSON:

{
"soap:Envelope": {
"soap:Header": "",
"xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/",
"soap:Body": {
"ns2:offerProductArrangementResponse": {
"xmlns:ns2": "http://LIB_SIM_SalesProcessManagement/IA_OfferProductArrangement",
"response": {
"productArrangement": {
"arrangementId": "317076",
"offeredProducts": {
"externalSystemProductIdentifier": [
{
"productIdentifier": "901",
"systemCode": "00107"
},
{
"productIdentifier": "201",
"systemCode": "10107"
},
{
"productIdentifier": "P_CLASSIC",
"systemCode": "00010"
},
{
"productIdentifier": "0071306000",
"systemCode": "00004"
},
{
"productIdentifier": "0071776000",
"systemCode": "00004"
}
],
"productIdentifier": "92",
"productoffer": {
"offerType": "2001"
},
"associatedFamily": {
"extsysprodfamilyidentifier": {
"productFamilyIdentifier": "502"
}
},
"productoptions": [
{
"optionsDescription": "Correspondence Default",
"optionsName": "Correspondence Default",
"optionsType": "CorrespDef",
"optionsValue": "Paper",
"optionsCode": "3521"
},
{
"optionsDescription": "Correspondence Option",
"optionsName": "Correspondence Option",
"optionsType": "CorrespOp",
"optionsValue": "Choice",
"optionsCode": "2944"
},
{
"optionsDescription": "Debit Card Funding",
"optionsName": "Debit Card Funding",
"optionsType": "DCF",
"optionsValue": "N",
"optionsCode": "3943"
},
{
"optionsDescription": "Product Priority",
"optionsName": "Product priority",
"optionsType": "PrdPriority",
"optionsValue": "5",
"optionsCode": "2658"
},
{
"optionsDescription": "Upsell Display Value",
"optionsName": "Upsell Display Value",
"optionsType": "UPSellDispval",
"optionsValue": "0",
"optionsCode": "2659"
},
{
"optionsDescription": "Account Switching",
"optionsName": "Account Switching",
"optionsType": "AccSwitching",
"optionsValue": "Y",
"optionsCode": "2662"
},
{
"optionsDescription": "VERDE PRODUCT ID",
"optionsName": "VERDE PRODUCT ID",
"optionsType": "VerdeProdId",
"optionsValue": "20051",
"optionsCode": "4523"
},
{
"optionsDescription": "Vantage Product Id for Verde",
"optionsName": "Vantage Product Id for Verde",
"optionsType": "VantProdIDVer",
"optionsValue": "20055",
"optionsCode": "4963"
},
{
"optionsDescription": "isVantage",
"optionsName": "isVantage",
"optionsType": "isVantage",
"optionsValue": "No",
"optionsCode": "6659"
},
{
"optionsDescription": "Overdraft Offer Flag",
"optionsName": "Overdraft Offer Flag",
"optionsType": "OD_Offer_Flag",
"optionsValue": "Y",
"optionsCode": "6905"
},
{
"optionsDescription": "Make_It_Joint",
"optionsName": "Make_It_Joint",
"optionsType": "MkItJoint",
"optionsValue": "1",
"optionsCode": "6975"
},
{
"optionsDescription": "Survey",
"optionsName": "Survey",
"optionsType": "Survey",
"optionsValue": "Y",
"optionsCode": "7288"
},
{
"optionsDescription": "Statement Option",
"optionsName": "Statement Option",
"optionsType": "StateOp",
"optionsValue": "Choice",
"optionsCode": "1099"
},
{
"optionsDescription": "Statement Default",
"optionsName": "Statement Default",
"optionsType": "StateDef",
"optionsValue": "Paper",
"optionsCode": "1770"
},
{
"optionsDescription": "Tariff",
"optionsName": "Tariff",
"optionsType": "TRF",
"optionsValue": "1",
"optionsCode": "2663"
}
],
"productName": "Classic Account"
},
"applicationType": "10001",
"xsi:type": "ns7:DepositArrangement",
"isOverdraftRequired": "true",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:ns7": "http://LIB_SIM_BO/BusinessObjects",
"primaryInvolvedParty": {
"auditData": [
{
"auditTime": "132551",
"auditType": "PARTY_EVIDENCE",
"auditDate": "12012018"
},
{
"auditTime": "132551",
"auditType": "ADDRESS_EVIDENCE",
"auditDate": "12012018"
},
{
"auditTime": "132551",
"auditType": "ADDRESS",
"auditDate": "12012018"
}
],
"isAuthCustomer": "false",
"cidPersID": "+00554133625",
"customerSegment": "3",
"individualIdentifier": "249894",
"newCustomerIndicator": "true",
"customerIdentifier": "2012794088",
"customerScore": [
{
"scoreResult": "ACCEPT",
"assessmentType": "EIDV",
"decisionText": "001",
"decisionCode": "I",
"assessmentEvidence": {
"addressStrength": "900",
"evidenceIdentifier": "4696198HL890678339009003211586646102",
"identityStrength": "900"
}
},
{
"scoreResult": "1",
"assessmentType": "ASM",
"referralCode": [
{
"code": "601",
"description": "Accept."
},
{
"code": "601",
"description": "Accept."
}
],
"scoreIdentifier": "647448142"
}
]
},
"arrangementType": "CA",
"applicationStatus": "1002",
"associatedProduct": {},
"conditions": [
{
"result": "No",
"name": "INTEND_TO_SWITCH"
},
{
"result": "true",
"name": "INTEND_TO_OVERDRAFT"
},
{
"result": "Y",
"name": "CHECK_BOOK_OFFERED_FLAG"
},
{
"result": "20",
"name": "DEBIT_CARD_RISK_CODE"
},
{
"result": "4",
"name": "OVERDRAFT_RISK_CODE"
}
],
"overdraftDetails": {
"amount": {
"amount": "3001"
}
}
},
"header": {
"interactionId": "ucoGI58OmuY0bfYXx2iLqta",
"LloydsHeaders": [
{
"prefix": "ns4",
"name": "ServiceRequest",
"nameSpace": "http://www.lloydstsb.com/Schema/Infrastructure/SOAP",
"value": {
"ns5:From": "10.245.211.214",
"xsi:type": "ns5:ServiceRequest",
"ns5:Action": "offerProductArrangement",
"ns5:ServiceName": "offerProductArrangement",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"ns5:mustReturn": "false",
"ns5:MessageId": "ucoGI58OmuY0bfYXx2iLqta"
}
},
{
"prefix": "ns4",
"name": "ContactPoint",
"nameSpace": "http://www.lloydstsb.com/Schema/Infrastructure/SOAP",
"value": {
"ns5:OperatorType": "Customer",
"ns5:ContactPointId": "0000777505",
"ns5:ApplicationId": "AL07618",
"ns5:InitialOriginatorId": "10.245.224.125",
"xsi:type": "ns5:ContactPoint",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"ns5:mustReturn": "false",
"ns5:InitialOriginatorType": "Browser",
"ns5:ContactPointType": "003"
}
},
{
"prefix": "ns5",
"name": "bapiInformation",
"nameSpace": "http://www.lloydstsb.com/Schema/Enterprise/LCSM",
"value": {
"ns4:BAPIId": "B001",
"xsi:type": "ns4:bapiInformation",
"ns4:BAPIOperationalVariables": {
"ns4:bForceHostCall": "false",
"ns4:bBatchRetry": "false",
"ns4:bPopulateCache": "false"
},
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"ns4:BAPIHeader": {
"ns4:acceptLanguage": {
"xsi:nil": "true"
},
"ns4:inboxidClient": "GX",
"ns4:cctmauthcd": {
"xsi:nil": "true"
},
"ns4:encVerNo": {
"xsi:nil": "true"
},
"ns4:sessionid": "ucoGI58OmuY0bfYXx2iLqta",
"ns4:useridAuthor": "UNAUTHSALE",
"ns4:userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36",
"ns4:chanidObo": {
"xsi:nil": "true"
},
"ns4:stpartyObo": {
"ns4:ocisid": "737704834",
"ns4:partyid": "+00263174828",
"ns4:host": "I"
},
"ns4:chanid": "IBL",
"ns4:ipAddressCaller": {
"xsi:nil": "true"
},
"ns4:chanctxt": "1",
"ns4:callerlineid": {
"xsi:nil": "true"
},
"ns4:chansecmode": "PWD"
}
}
},
{
"prefix": "lgsm",
"name": "Security",
"nameSpace": "http://LB_GBO_Sales/Messages",
"value": {
"mustReturn": "false",
"ns3:UsernameToken": {
"ns3:Username": "UNAUTHSALE",
"ns3:UNPMechanismType": "NTLM",
"Id": "LloydsTSBSecurityToken",
"ns3:UserType": "013"
},
"xsi:type": "ns3:SecurityHeaderType",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance"
}
}
],
"businessTransaction": "OfferProductArrangement",
"channelId": "LTB"
}
},
"xmlns:ns5": "http://www.lloydstsb.com/Schema/Infrastructure/SOAP",
"xmlns:ns3": "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
"xmlns:ns4": "http://www.lloydstsb.com/Schema/Enterprise/LCSM"
}
}
}
}

最佳答案

我认为你可以使用 XPath 构建你的函数或JsonPath作为您的解决方案的基础

关于java - 使用Java解析XML转换为Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48228230/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com