gpt4 book ai didi

java - 如何解析来自 .net webservice 的 diffgram anytype 响应

转载 作者:行者123 更新时间:2023-11-30 11:06:28 25 4
gpt4 key购买 nike

我从任何类型格式的 .net Web 服务收到以下响应。我需要解析此格式并读取格式中提供的 RemMessage 和 INVM_ID 等数据值。我无法解析此格式并获取适当的值。java代码是..

public class WebService {

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
SoapObject request = new SoapObject(NAMESPACE, webMethName);
androidHttpTransport.debug=true;
androidHttpTransport.setXmlVersionTag("");
// Property which holds input parameters
PropertyInfo sayHelloPI = new PropertyInfo();
// Set Name
sayHelloPI.setName("UserId");
// Set Value
sayHelloPI.setValue("41");
// Set dataType
sayHelloPI.setType(String.class);
// Add the property to request object
request.addProperty(sayHelloPI);
//Set envelope as dotNet
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
try {
List<GetReminder> reminders = new ArrayList<>();
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
// Invoke web service
androidHttpTransport.call(SOAP_ACTION, envelope);
// Get the response
String response=androidHttpTransport.responseDump;
Log.d("Result --- ", response.toString() );
SoapObject obj=(SoapObject)envelope.getResponse();
System.out.println("obj---->" + obj.toString());
} catch (SocketException e) {
Log.e("Error :" ,"Error " +e.getMessage());
//Print error
e.printStackTrace();
//Assign error message to resTxt
resTxt = "Error occured";
}
catch (XmlPullParserException e1)
{
String resp=androidHttpTransport.responseDump;
e1.printStackTrace();
resTxt = "Error occured";
}
//Return resTxt to calling object
return resTxt;
}
}

这会返回如下响应,我需要读取这些参数 RemMessage 和 InvM_Id 的数据,并且我有 GetReminder 类

public class GetReminder implements Serializable {
private String RemMessage;
private int InvM_Id;
private int DocType;
private int PrmR_TypeId;
private int PrmR_Id;

public String getRemMessage() {
return RemMessage;
}

public void setRemMessage(String remMessage) {
RemMessage = remMessage;
}

public int getInvM_Id() {
return InvM_Id;
}

public void setInvM_Id(int invM_Id) {
InvM_Id = invM_Id;
}

public int getPrmR_TypeId() {
return PrmR_TypeId;
}

public void setPrmR_TypeId(int prmR_TypeId) {
PrmR_TypeId = prmR_TypeId;
}

public int getDocType() {
return DocType;
}

public void setDocType(int docType) {
DocType = docType;
}

public int getPrmR_Id() {
return PrmR_Id;
}

public void setPrmR_Id(int prmR_Id) {
PrmR_Id = prmR_Id;
}

}

响应格式

 anyType {
schema = anyType {
element = anyType {
complexType = anyType {
choice = anyType {
element = anyType {
complexType = anyType {
sequence = anyType {
element = anyType {

};
element = anyType {

};
element = anyType {

};
element = anyType {

};
element = anyType {

};
};
};
};
};
};
};
};
diffgram = anyType {
NewDataSet = anyType {
Table = anyType {
RemMessage = ExeedDiscountLimitonInvoicedatedon05 / 03 / 2015forCSHAH,
from3 - LokhandwalaShowroom;
InvM_Id = 77693;
DocType = 3;
PrmR_TypeId = 3;
PrmR_Id = 1820;
};
};
};
}

这只是一个单一的消息格式(RemMessage),我将获得 RemMessage 的多个条目。

最佳答案

您在这篇文章中包含了 soap 响应的 XML 表示:Parsing Complex Soap Response with diffgram .我们可能会看到,第一个元素(“schema = anyType {...”)只是类型“NewDataSet”的定义。因此,您只需要解析第二部分,即保存 GetReminder 模型的数据。代码在你最后一次发帖下 https://stackoverflow.com/a/30059614/4114960

关于java - 如何解析来自 .net webservice 的 diffgram anytype 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29297741/

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