0

I'm using volley to send JSON object from android code to C# webservice. Below is the Android code:


 List<JSONObject > items = new ArrayList<JSONObject>(); 
 JSONObject field = new JSONObject();
 String base64String = Base64.encodeToString(image_in_byte, Base64.DEFAULT);
 String file_str = file.getName();
 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss.SS");
 String dateFormat = sdf.format(date);
 field.put("ID", file_str);
 field.put("IsTemp", "true");
 field.put("Image", base64String);
 field.put("Type", "JPEG" );
 items.add(field);
 JSONObject temp = new JSONObject();
 temp.put("field1", "data1");
 temp.put("field2", "data2");
 temp.put("Input1", items);
 temp.put("field3", dateFormat);
 temp.put("field4", "test");
 temp.put("field5", dateFormat);
 temp.put("field6", "test");
 try
 {
 String SERVER = "http:// webservice url";
 JsonObjectRequest jsObjRequest = new
 JsonObjectRequest(Request.Method.POST,SERVER,temp, 
 new Response.Listener<JSONObject>()
 {
 @Override
 public void onResponse(JSONObject response) {
 System.out.println(response);
 //hideProgressDialog();
 }
 },
 new Response.ErrorListener()
 {
 @Override
 public void onErrorResponse(VolleyError error)
 {
 Toast.makeText(getApplicationContext(), 
 error.toString(), Toast.LENGTH_SHORT).show();
 }
 });
 queue.add(jsObjRequest);
 }
 catch(Exception ex)
 {
 ex.printStackTrace();
 }

Below is the C# webservice


 [AllowAnonymous]
 [Route("webservice")]
 [HttpPost]
 public async Task<IHttpActionResult> UploadData(Data F_Data)
 {
 if (F_Data == null ||F_Data.Input1 == null)
 {
 return BadRequest("Input parameter is empty");
 } 
 }
 public class Input_F
 {
 public int ID { get; set; }
 public bool IsTemp { get; set; }
 public string Image { get; set; }
 public string Type { get; set; }
 }
 public class Data
 {
 public string field1 { get; set; }
 public string field2 { get; set; }
 public List<Input_F> Input1{ get; set; }
 public DateTime field3 { get; set; }
 public string field4 { get; set; }
 public DateTime field5{ get; set; }
 public string field6 { get; set; }
 }

In the UploadData routine, I'm getting F_Data.Input1 as null. I'm able to get rest of the fields of Data class but Input1 is null. I'm not sure if I'm sending Input1 correctly from my android code, any pointers would be of great help.

asked Apr 24, 2016 at 11:23
2
  • If you Google Volley and ArrayList you will find everyone first converting it to Map<string, string> Commented Apr 24, 2016 at 11:55
  • Thanks Crowcoder for the pointer, i was able to fix it. We need to first convert to Map<string, string> and then send the data. This post helped me in fixing this. Commented Apr 24, 2016 at 12:36

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.