需要知道字符串的POST JSON Body格式和List <string> ormlite-servicestack

时间:2015-05-18 13:25:32

标签: c# web-services asp.net-web-api servicestack ormlite-servicestack

对于POST List和字符串,我需要JSON Body FORMAT 的专业知识帮助。我已经通过Service Stack开发了JSON,C#Web服务。我想发布时间戳列表&#39;以及String&#39; EmployeeId&#39;。但是在接收端(Web服务)我只得到字符串类型&#39; EmployeeId&#39;与
    列表时间戳为NULL。我尝试了以下几种方式。

Webservice名称:

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; } 
}

我通过Firefox HttpRequester实用程序发布测试。

JSON格式的BODY /内容我试过如下,但没有什么工作正常。我不知道我在哪里做错了:

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"}]}

1 个答案:

答案 0 :(得分:1)

与此请求DTO匹配的JSON正文:

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

应该是这样的:

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"]}

e.g。只有1个JSON对象(整个DTO)和Timestamp只是一个字符串数组。

每当您怀疑并想知道JSON应该是什么样时,您就可以序列化该对象,例如:

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();