gpt4 book ai didi

java - 从网络服务请求信息时未获得完整结果

转载 作者:行者123 更新时间:2023-12-01 14:35:42 25 4
gpt4 key购买 nike


我有一个编写的 Web 服务,以及我编写的用于调用其方法之一的 java 方法。该服务返回一个 JSON 字符串。

由于 NDA 协议(protocol),我无法在此处发布任何服务代码,但这也无关紧要,因为从服务本身激活该方法时,它会给出正确的结果。

基本上,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.
//************************************************************

感谢您的帮助!

最佳答案

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

关于java - 从网络服务请求信息时未获得完整结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16505515/

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