0

Here is my code :

   {
     "VisitorDetails":[
         {
            "Name":"Ramesh",
            "Gender":"Male",
            "Age":24,
            "MobileNo":9502230173,
            "LandLine":"040140088",
            "EmailId":"rameshkandula24@gmail.com",
            "CreatedOn":"08-25-2016",
            "Address":"Hyderabad",
            "Profession":"Software",
            "FamilyMembers":5,
            "HomeTown":"Gannavaram",
            "MedicalHealing":"Noooooo",
            "Isinterestedwithcompanies":1,
            "IsBetterlivingStandards":1,
            "IsInterestedinConference":1,
            "VisitorExcites":[1,2,3]
            "jsonkey" : "rUinterested"

        }
    ]
}
swiftBoy
  • 35,607
  • 26
  • 136
  • 135
M.praveen
  • 11
  • 7
  • pls anyone Know answer tell me > I am freshere in android – M.praveen Oct 04 '16 at 07:26
  • Create JSOnArray put all the data between [] braces, then create a json object and put arrray in this object key as VisitorDetails. – D.J Oct 04 '16 at 07:27

3 Answers3

0
try {

    JSONArray arry = new JSONArray();

    JSONObject iner = new JSONObject();

    iner.put("Name", "nmae");

    //all detail to iner

    arry.put(iner);

    JSONObject outer = new JSONObject();

    outer.put("VisitorDetails", arry);
}

catch (Exception e){
}
brahmy adigopula
  • 617
  • 3
  • 15
D.J
  • 1,439
  • 1
  • 12
  • 23
0

Update : add this in your gradle(app level)

compile 'com.android.volley:volley:1.0.0'

developing from Bansal ans .

your json data

JSONArray arry = new JSONArray();
        try {
            JSONObject jsonobject_one = new JSONObject();

            jsonobject_one.put("Name", "Name");
// add all details like this

arry.put(jsonobject_one);
            JSONObject jsonobject_TWO = new JSONObject();
            jsonobject_TWO.put("VisitorDetails", arry);

        }catch (JSONException e) {
                e.printStackTrace();
        }

Then Your jsonRequest

JsonArrayRequest jsonArryReq = new JsonArrayRequest(
        Request.Method.POST,url, arry,
        new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                Log.d(TAG, response.toString());


            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d(TAG, "Error: " + error.getMessage());

            }
        }) {

    /**
     * Passing some request headers
     * */
   @Override
            protected Map<String, String> getParams()
            {
                Map<String, String> param = new HashMap<String, String>();
                if (!GetMethod) {
                    param.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
                    return param;
                }
                return param;
            }
sivaBE35
  • 1,876
  • 18
  • 23
0
 final JSONObject jsonObject=new JSONObject();
            try {
                JSONArray jsonArray=new JSONArray();

                JSONObject innerobject=new JSONObject();

                innerobject.put("Name",Name);
                innerobject.put("Address",Country);

                jsonArray.put(innerobject);

                jsonObject.put("VisitorDetails",jsonArray);


            }catch (Exception e){
                e.printStackTrace();
            }

            JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, URL,jsonObject, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    // do something...
                    Toast.makeText(MainActivity.this, "your data successfully register", Toast.LENGTH_SHORT).show();
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    // do something...
                    Toast.makeText(MainActivity.this, "your data not register", Toast.LENGTH_SHORT).show();
                }
            }) {

                /**
                 * Passing some request headers
                 */
                @Override
                protected Map<String, String> getParams() {
                    Map<String, String> param = new HashMap<String, String>();

                        param.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
                        return param;
                }
            };
M.praveen
  • 11
  • 7
  • I am using com.mcxiaoke.volley:library-aar:1.0.0 library – M.praveen Oct 04 '16 at 10:54
  • com.mcxiaoke.volly:library-arr:1.0.0 library is deprecated. – sivaBE35 Oct 04 '16 at 12:26
  • thanxs@siva35,but i am updated 'com.android.volley:volley:1.0.0' Now i am getting error Unexpected response code 400 pls solve this, i am android fresher ,now first time hitting the server ,pls help me – M.praveen Oct 04 '16 at 12:49
  • remove this if (!GetMethod) { param.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); return param; } – sivaBE35 Oct 04 '16 at 12:52
  • I have an error Unexpeted error 400 in above code run any one pls solve this – M.praveen Oct 05 '16 at 05:39