書かれた Web サービスと、そのメソッドの 1 つを呼び出すために書いた 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.
//************************************************************
助けてくれてありがとう!