POSTing a DateTime from Android to a WCF RESTful JSON Service

前端 未结 4 1223
醉话见心
醉话见心 2021-02-10 09:11

I\'m trying to send a DateTime as a parameter to a method exposed over a WCF RESTful service with JSON encoding. The request looks like this:

POST h         


        
4条回答
  •  广开言路
    2021-02-10 09:24

    This is code I use to send from Android Java to .NET WebApp. Create a JSON object with a date in the W3C XML schema:

    Calendar myCalendarObj = Calendar.getInstance(); // Snap a moment in time
    
    JSONObject jObj = new JSONObject(); // Create a JSON object (org.json.JSONObject)
    
    SimpleDateFormat jsonDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); // from java.text.SimpleDateFormat
    String senddate = jsonDateFormat.format(myCalendarObj.getTime());
    jObj.put("a_date_field", senddate);
    

提交回复
热议问题