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.