Nservicekit反序列化
Nservicekit deserialization
本文关键字:反序列化 Nservicekit 更新时间:2023-09-26
我正试图将一个对象发布到nserviekit Web服务,请求有我的对象,但属性不受影响。但是当我使用JsonConvert进行反序列化时。DeserializeObject我的列表对象已正确填充。有人能帮我做这个吗?我做错了什么?非常感谢。
我正在使用以下代码来实现
[Route("/LogbookRegistries", Summary = @"Posts an List type of LogbookRegistry")]
public class LogbookRegistries
{
public List<LogBookRegistry> list { get; set; }
}
public class LogbookRegistriesService : Service
{
public object Options(LogbookRegistries request)
{
return true;
}
public LogbookRegistriesResponse Post(LogbookRegistries request)
{
var list = JsonConvert.DeserializeObject<List<LogBookRegistry>>(Request.FormData["list"]) ;
Boolean thereAreErrors = false;
// if (request.LogbookRegistriesList == null) throw new ArgumentNullException("Cant continue passed data is null");
try
{
// DataBase.SaveList<LogBookRegistry>(request.LogbookRegistriesList);
}
catch (Exception ex)
{
thereAreErrors = true;
}
return new LogbookRegistriesResponse { ResponseStatus = new ResponseStatus { Message = thereAreErrors ? @"There were errors while saving data." : @"Posted data saved succesfully." } };
}
public LogbookRegistriesResponse Get(LogbookRegistries request)
{
var list = DataBase.GetAll<LogBookRegistry>();
return new LogbookRegistriesResponse { Data=list };
}
}
public class LogbookRegistriesResponse
{
public ResponseStatus ResponseStatus { get; set; }
public List<LogBookRegistry> Data {get;set;}
}
public partial class LogBookRegistry
{
public LogBookRegistry()
{
this.LogBookRegistryDetails = new HashSet<LogBookRegistryDetail>();
}
public string code { get; set; }
public System.DateTime date { get; set; }
public int locationId { get; set; }
public int actionTypeId { get; set; }
public Nullable<int> deviceId { get; set; }
public string remarks { get; set; }
public virtual Location Location { get; set; }
public virtual Item Item { get; set; }
public virtual ICollection<LogBookRegistryDetail> LogBookRegistryDetails { get; set; }
public virtual Device Device { get; set; }
}
在javascript方面,我正在使用
$.ajax({
type: "POST",
url: 'http://localhost:49321/LogbookRegistries?',
data: {"list":JSON.stringify( [
{
"LogRegistryDetails": "",
"id": "0",
"locationId": "2",
"actionTypeId": "2",
"code": "TRP-OUT-Palmetal-20150310_151929",
"active": "true",
"date": "2015-03-10 15:19:29",
"deviceId": "1",
"remarks": ""
}
])} ,
dataType: 'json',
})
.done(function (data, textStatus, jqXHR) {
debugger;
alert('done');
})
.fail(function (jqXHR, textStatus, errorThrown) {
debugger;
alert('fail');
});
您需要JSON.stringify()
整个JSON数据对象,而不仅仅是列表项数组。然后ServiceStack可以自动取消对请求的序列化。
$.ajax({
type: "POST",
url: 'http://localhost:49321/LogbookRegistries?',
data: JSON.stringify( {"list":[
{
"LogRegistryDetails": "",
"id": "0",
"locationId": "2",
"actionTypeId": "2",
"code": "TRP-OUT-Palmetal-20150310_151929",
"active": "true",
"date": "2015-03-10 15:19:29",
"deviceId": "1",
"remarks": ""
}
]}) ,
dataType: 'json',
})
.done(function (data, textStatus, jqXHR) {
debugger;
alert('done');
})
.fail(function (jqXHR, textStatus, errorThrown) {
debugger;
alert('fail');
});
相关文章:
- 有没有一个Nodejs库可以序列化和反序列化命名组件的路径(比如URL路径名)
- 是否可以在javascript中反序列化java对象
- 如何在C#中反序列化json对象
- Nservicekit反序列化
- 无法反序列化 java.util.List 的实例VALUE_STRING
- 正在反序列化jQuery.Serialize的结果(到数组,而不是到窗体)
- 使用 JavaScript 进行反序列化
- Three.js-如何反序列化几何体.toJSON()?(几何体.fromJSON在哪里?)
- .NET服务中的JSON反序列化-can'不能解决这个问题
- 如何:从javascript反序列化C#对象
- 护照.js:如何避免序列化和反序列化用户
- 如何在 Express/Node.js 中反序列化 JSON 数据
- 在 javascript 中序列化和反序列化数组
- PHP 反序列化 JS 序列化的变量字符串
- Javascript:反序列化对象和混合方法
- 如何使用 Dojo.fromJson 反序列化包含控制字符的 Json 对象
- 当错误时清除cookie 使用护照反序列化用户.js
- 部分平展的 JSON 的反序列化
- JavaScript 中的 JSON 反序列化
- 使用表单的当前状态序列化和反序列化表单