【问题标题】:Not getting full results when requesting info from a web service从 Web 服务请求信息时未获得完整结果
【发布时间】:2013-05-12 08:27:14
【问题描述】:


我有一个书面的 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.
            //************************************************************

感谢您的帮助!

【问题讨论】:

  • 您是否使用 JSON 进行 SOAP 响应?
  • 当然。结果为 JSON 格式。
  • 您正在尝试将 JSON 转换为 Java 对象,并且在此过程中数组的第一行被跳过?
  • 没有。看起来从一开始它就跳过了第一个。这与我使用 JSON 的事实无关。我从服务中得到的字符串是错误的

标签: java android json soap


【解决方案1】:

不敢相信...服务中的 inventoryID 属性不是大写字母... 奇怪的是它使结果错误,而不仅仅是给出错误..

【讨论】:

    【解决方案2】:

    您是否重新检查了创建 String form InputStream 的过程?使用的编码可能是。我不确定这是否是原因,但我曾经因为它而遇到过同样的问题。

    【讨论】:

    • 试过了。改了编码,还是一样的问题
    猜你喜欢
    • 1970-01-01
    • 2015-09-28
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 2013-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多