简体   繁体   中英

Need to know POST JSON Body Format for string and List<string> ormlite-servicestack

I need the expertise help for JSON Body FORMAT for POST List and string. I have developed the JSON , C# web services by Service Stack. I would like to Post the List of 'Timestamp' along with String 'EmployeeId'. But at receiving end (Web Service) I am getting only string type 'EmployeeId'with
List Timestamp is NULL. I have tried the number of ways as below.

Webservice Name:

http://192.168.1.109/EmployeeDatabase/json/reply/UpdateSyncStatus_EmployeeId_Timestamp

[Route("/UpdateSyncStatus_EmployeeId_Timestamp", "POST")]
public class UpdateSyncStatus_EmployeeId_Timestamp
{
    public string EmployeeId { get; set; }
    public List<string> Timestamp { get; set; } 
}

I am Posting for test via Firefox HttpRequester utility.

The BODY / Content in JSON format I have tried as below but nothing is working fine. I do not know where I am doing mistake:

1.

{"EmployeeId" : "gopsw_15_05_2015_17_17_571"},[{"Timestamp" : "2015-05-18T12:36:04.379"  ,  "Timestamp" : "2015-05-18T12:38:04.379" ,  "Timestamp" : "2016-05-18T12:38:04.379"}]

2.

{"EmployeeId" : "gopsw_15_05_2015_17_17_571"}, Timestamp : ["2015-05-18T12:36:04.379"  , "2015-05-18T12:38:04.379" ]

3.

{"EmployeeId" : "gopsw_15_05_2015_17_17_571"},[{"Timestamp" : "2015-05-18T12:36:04.379"} , {"Timestamp" : "2015-05-18T12:38:04.379"}]

4.

{"EmployeeId" : "gopsw_15_05_2015_17_17_571"},  "Timestamp" : [{"2015-05-18T12:36:04.379"} , {"2015-05-18T12:38:04.379"}] 

5.

{"EmployeeId" : "gopsw_15_05_2015_17_17_571"},  {"Timestamp"} : [{"2015-05-18T12:36:04.379"} , {"2015-05-18T12:38:04.379"}]

6.

{"EmployeeId" : "gopsw_15_05_2015_17_17_571"},  {{"Timestamp"} : [{"2015-05-18T12:36:04.379"} , {"2015-05-18T12:38:04.379"}]}

The JSON Body that matches this Request DTO:

[Route("/UpdateSyncStatus_EmployeeId_Timestamp", "POST")]
public class UpdateSyncStatus_EmployeeId_Timestamp
{
    public string EmployeeId { get; set; }
    public List<string> Timestamp { get; set; } 
}

Should look like:

POST /UpdateSyncStatus_EmployeeId_Timestamp

{"EmployeeId":"gopsw_15_05_2015_17_17_571","Timestamp":["2015-05-18T12:36:04.379","2015-05-18T12:38:04.379"]}

eg There's only 1 JSON Object (the entire DTO) and Timestamp is just an array of strings.

Whenever you're in doubt and want to know what the JSON should look like you can just serialize the object, eg:

var json = new UpdateSyncStatus_EmployeeId_Timestamp {
    EmployeeId = "gopsw_15_05_2015_17_17_571",
    Timestamp = new []{"2015-05-18T12:36:04.379","2015-05-18T12:38:04.379"}.ToList()
}.ToJson();

json.Print();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM