pass arraylist bean from android to webservice php

Posted by user1547432 on Stack Overflow See other posts from Stack Overflow or by user1547432
Published on 2013-06-12T04:32:18Z Indexed on 2013/11/03 15:54 UTC
Read the original article Hit count: 139

Filed under:
|
|
|

i'm newbie in android with web service

i'm trying to pass arraylist from android to webservice php server

here's my bean code:

public class ExpressionBean {
    public static final String EXPRESSION_ID = "expressionID";
    public static final String EXPRESSION_TEXT = "expressionText";
    public static final String ANS_TEXT1 = "ansText1";
    public static final String ANS_TEXT2 = "ansText2";
    public static final String ASSESSEE_ANSWER = "assesseeAnswer";

    private String expressionID;
    private String expressionText;
    private String ansText1;
    private String ansText2;
    private String assesseeAnswer;

    public String getExpressionID() {
        return expressionID;
    }

    public void setExpressionID(String expressionID) {
        this.expressionID = expressionID;
    }

    public String getExpressionText() {
        return expressionText;
    }

    public void setExpressionText(String expressionText) {
        this.expressionText = expressionText;
    }

    public String getAnsText1() {
        return ansText1;
    }

    public void setAnsText1(String ansText1) {
        this.ansText1 = ansText1;
    }

    public String getAnsText2() {
        return ansText2;
    }

    public void setAnsText2(String ansText2) {
        this.ansText2 = ansText2;
    }

    public String getAssesseeAnswer() {
        return assesseeAnswer;
    }

    public void setAssesseeAnswer(String assesseeAnswer) {
        this.assesseeAnswer = assesseeAnswer;
    }

}

and here's my doInBackround on async task :

protected Boolean doInBackground(Void... params) {
            // TODO: attempt authentication against a network service.

            boolean result = false;
            // test = new TestBean();

            // int resultTest = 0;
            UserFunctions userFunction = new UserFunctions();

            Log.d(TAG, "UID : " + mEmail);
            // Log.d(TAG, "resultTest : " + resultTest);
            JSONObject jsonTest = userFunction.storeTest(mEmail);
            Log.d(TAG, "After JSON TEST ");

            try {
                if (jsonTest.getString(KEY_SUCCESS) != null) {
                    String res = jsonTest.getString(KEY_SUCCESS);
                    JSONObject testData = jsonTest.getJSONObject(TAG_TEST);
                    test = new TestBean();
                    test.setTestid(testData.getInt(TAG_TEST_ID));
                    test.setUid(testData.getInt(TAG_UID));
                    JSONArray list = new JSONArray();
                    String list2;
                    for (int position = 0; position < expressionList.size(); position++) {
                        Gson gson = new Gson();
                        list.put(gson.toJson(expressionList.get(position)));

                    }
                    Log.d(TAG, "JSONArray list coy : " + list);
                    UserFunctions uf = new UserFunctions();

                    JSONObject jsonHistoryList = new JSONObject();
                    jsonHistoryList = uf.storeHistoryList(list.toString());
                    if (Integer.parseInt(res) == 1) {
                        result = true;
                        finish();
                    } else {
                        result = false;
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
                return false;
            }

            // TODO: register the new account here.
            return result;
        }

and here's storeHistoryList Method :

public JSONObject storeHistoryList(String list) {

        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("tag", storeHistory_tag));
        params.add(new BasicNameValuePair("list", list));

        JSONObject json = jsonParser.getJSONFromUrl(URL, params);
        return json;
    }

i want to pass list to web service

list is an arraylist ExpressionBean

i used gson for convert bean to json

but when i execute, the log said

"error parsing data...

jsonarray cannot be converted to jsonobject

what i must to do? thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about android