我有一个书面的 Web 服务,以及我编写的用于调用其中一个方法的 java 方法。该服务返回一个JSON
字符串。
由于 NDA 协议,我无法在此处发布任何服务代码,但这也无关紧要,因为从服务本身激活方法时,它会给出正确的结果。
基本上,java 代码会跳过数组中的第一个单元格。
这是原始结果(直接来自服务):
{"message":"Success","success":"1","Table" : [{"priceline" : "Price 1","percaret_price" : "1430.0000","total" : "757.9000","discount" : "-45.00"},{"priceline" : "Price 2","percaret_price" : "","total" : "","discount" : ""},{"priceline" : "Price 3","percaret_price" : "","total" : "","discount" : ""},{"priceline" : "Cash","percaret_price" : "","total" : "","discount" : ""},{"priceline" : "MSRP","percaret_price" : "","total" : "","discount" : ""}]}
这是java代码的结果:
{"message":"Success","success":"1","Table" : [{"priceline" : "Price 2","percaret_price" : "","total" : "","discount" : ""},{"priceline" : "Price 3","percaret_price" : "","total" : "","discount" : ""},{"priceline" : "Cash","percaret_price" : "","total" : "","discount" : ""},{"priceline" : "MSRP","percaret_price" : "","total" : "","discount" : ""}]}
*为了便于阅读,您可以使用 json 查看器:http: //jsonviewer.stack.hu/
这是我的java代码(所有变量都是正确的。如果不是,则没有返回结果):
SoapObject request = new SoapObject(NAMESPACE, COST_INFORMATION_NAME);
// Use this to add parameters
request.addProperty("user_id", login.getUser_id());
request.addProperty("company_id", login.getCompany_id());
request.addProperty("inventoryID", inventoryId);
// Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
// this is the actual part that will call the webservice
androidHttpTransport.call(COST_INFORMATION_ACTION, envelope);
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject) envelope.bodyIn;
if (result != null) {
String res = result.getPropertyAsString(0);
//************************************************************
//Everything else isn't relevant, the res variable contains the result I put above the code.
//************************************************************
谢谢您的帮助!