How to get the result for return statement from JSON parsing?

Posted by blankon91 on Stack Overflow See other posts from Stack Overflow or by blankon91
Published on 2012-06-19T01:45:52Z Indexed on 2012/06/19 3:16 UTC
Read the original article Hit count: 273

Filed under:
|
|

I've follow the code for parsing the value with JSON from here, but I get the problem in my return statement. I want to put the parsing result into my return statement. How to do that?


Here is my code:

public String MASUK(String user, String password)
    {
        SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);

        PropertyInfo pi = new PropertyInfo();
        pi.setName("ccduser");
        pi.setValue(user);
        pi.setType(String.class);
        request.addProperty(pi);

        PropertyInfo pi2 = new PropertyInfo();
        pi2.setName("password");
        pi2.setValue(password);
        pi2.setType(String.class);
        request.addProperty(pi2);


        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);

        HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
        try
        {
            httpTransport.call(SOAP_ACTION, envelope);
            SoapObject resultSOAP = (SoapObject) envelope.bodyIn;

            /* gets our result in JSON String */
            String ResultObject = resultSOAP.getProperty(0).toString();

            resultSOAP = (SoapObject) envelope.bodyIn;
            ResultObject = resultSOAP.getProperty(0).toString();

            if (ResultObject.startsWith("{")) { // if JSON string is an object
                JSONObj = new JSONObject(ResultObject);
                Iterator<String> itr = JSONObj.keys();
                while (itr.hasNext()) {
                    String Key = (String) itr.next();
                    String Value = JSONObj.getString(Key);
                    BundleResult.putString(Key, Value);
                    // System.out.println(bundleResult.getString(Key));
                }
            } 

            else if (ResultObject.startsWith("[")) { // if JSON string is an array
                JSONArr = new JSONArray(ResultObject);
                System.out.println("length" + JSONArr.length());
                for (int i = 0; i < JSONArr.length(); i++) {
                    JSONObj = (JSONObject) JSONArr.get(i);
                    BundleResult.putString(String.valueOf(i), JSONObj.toString());
                    // System.out.println(bundleResult.getString(i));
                } 
            }
        }
        catch (Exception exception)
        {

        }

        return null;

    }

© Stack Overflow or respective owner

Related posts about android

Related posts about JSON