我有一个书面的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.
//************************************************************
感谢您的帮助!
答案 0 :(得分:1)
无法相信......服务中的inventoryID属性不是大写字母...... 很奇怪虽然它导致结果错误,但并没有给出错误..
答案 1 :(得分:0)
您是否重新检查了创建String表单InputStream的过程?使用的编码可能是。我不确定这是否是原因,但由于它曾经有过同样的问题。