如何在Android中将arraylist发布到json webservice中

时间:2012-11-01 07:13:52

标签: json web-services

这里是我的代码使用json http post方法凭证对象有两个参数用户名和密码和alist类型arraylist有5个参数

{

    {
        public static ProfilesResponseJson callWebServiceJson(Credential Credentials, ArrayList<A> alist) {

        try {

            System.out.println("-----alist---"+alist.size());



            for(int j=0;j<alist.size();j++)
            {
                System.out.println(j+"---alist.get().get--getDataType--"+alist.get(j).getDataType());
                System.out.println(j+"---alist.get().get--getRawData--"+alist.get(j).getRawData());
                System.out.println(j+"---alist.get().get--getScanDeviceSN--"+alist.get(j).getScanDeviceSN());
                System.out.println(j+"---alist.get().get---getScanKey-"+alist.get(j).getScanKey());
                System.out.println(j+"---alist.get().get--getScannerProfileID--"+alist.get(j).getScannerProfileID());
                System.out.println(j+"---alist.get().get--getScanTime--"+alist.get(j).getScanTime());


                //StringEntity se = new StringEntity("{'attendeeCredentials':{'UserID':'"+attendeeCredentials.getUserID()+"','Password':'"+attendeeCredentials.getPassword()+"'},' scanprofilelist:':{ scanprofile:['RawData':'"+scanProfileList.get(j).getRawData()+""]}");
                 se=new StringEntity("{'Credentials':{'UserID':'"+Credentials.getUserID()+"','Password':'"+attendeeCredentials.getPassword()+"'},'scanprofilelist':{'ScanProfile':['RawData':'"+alist.get(j).getRawData()+"','DataType':'"+alist.get(j).getDataType()+"','ScanKey':'"+alist.get(j).getScanKey()+"','ScannerProfileID':'"+alist.get(j).getScannerProfileID()+"','ScanDeviceSN':'"+alist.get(j).getScanDeviceSN()+"','ScanTime':'"+alist.get(j).getScanTime()+"']}}");

            }



            DefaultHttpClient httpclient = new DefaultHttpClient();
            httpost.setEntity(se);
            httpost.setHeader("Accept", "application/json");
            httpost.setHeader("Content-type", "application/json");

            ResponseHandler responseHandler = new BasicResponseHandler();
            String response = httpclient.execute(httpost, responseHandler);

            return ParseResult(response);
        } catch (Exception exep) {
            System.err.println(exep.toString());
        }

        return null;
    }
}

0 个答案:

没有答案