My code is :
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
OPERATION_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
try
{
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
System.out.println("response : " + response.toString());
}
The response shown in the console :
03-21 14:23:30.532: INFO/System.out(4311): response : Map{item=anyType{key=2; value=Apple; }; item=anyType{key=1; value=Orange; }; }
How can i parse this JSOn Object.. I have tried with
JSONObject jObject = new JSONObject( response.toString());
But an exception is thrown :
03-21 14:17:03.423: WARN/System.err(4210): org.json.JSONException: Value Map of type java.lang.String cannot be converted to JSONObject
My web service method :
public JSONObject getContactNames(){
JSONObject names = load();
System.out.println("names "+names);
return names;
}
WSDL :
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://service.asset.ey.com" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="getContactNames">
<complexType/>
</element>
<element name="getContactNamesResponse">
<complexType>
<sequence>
<element name="getContactNamesReturn" type="xsd:anyType"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="getContactNamesRequest">
<wsdl:part element="impl:getContactNames" name="parameters"/>
</wsdl:message>
<wsdl:message name="getContactNamesResponse">
<wsdl:part element="impl:getContactNamesResponse" name="parameters"/>
</wsdl:message>
<wsdl:portType name="ContactDetails">
<wsdl:operation name="getContactNames">
<wsdl:input message="impl:getContactNamesRequest" name="getContactNamesRequest"/>
<wsdl:output message="impl:getContactNamesResponse" name="getContactNamesResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ContactDetailsSoapBinding" type="impl:ContactDetails">
<wsdlsoap:b开发者_JAVA百科inding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getContactNames">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getContactNamesRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getContactNamesResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
Please Help in parsing the response:
Map{item=anyType{key=2; value=Apple; }; item=anyType{key=1; value=Orange; }; }
Is not valid json object. for more info how to construct json objects check the docs http://www.json.org/javadoc/org/json/JSONObject.html
精彩评论