Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中解析JSON时出现异常_Android_Json_Ksoap2_Android Ksoap2 - Fatal编程技术网

android中解析JSON时出现异常

android中解析JSON时出现异常,android,json,ksoap2,android-ksoap2,Android,Json,Ksoap2,Android Ksoap2,我的代码是: SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoa

我的代码是:

     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());
}
控制台中显示的响应:

03-21 14:23:30.532: INFO/System.out(4311): response : Map{item=anyType{key=2; value=Apple; }; item=anyType{key=1; value=Orange; }; }
如何解析此JSOn对象。。我试过了

JSONObject jObject = new JSONObject( response.toString()); 
但会引发一个异常:

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
我的web服务方法:

 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:binding 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>

请帮助分析响应:

映射{item=anyType{key=2;value=Apple;};item=anyType{key=1;value=Orange;};}


不是有效的json对象。有关如何构造json对象的更多信息,请检查文档

您得到的响应不是json格式的…这是从web服务调用检索到的信息。。我已经给出了我的wsdl和webservice方法,如果您使用某个服务获取响应,请检查您的服务,但响应肯定是json。您可以使用这个在线检查器来验证它是否是json。尝试在服务中查找问题。我得到的响应为{“2”:“Apple”,“1”:“Orange”},并且它是有效的。。我如何解析它你所说的parse.JSONObject jobj=newjsonobject({“2”:“Apple”,“1”:“Orange”})是什么意思;jobj.getString(“2”)//返回键2的值,即Apple jobj.getString(“1”)//返回橙色