我正在研究这个需要序列化JSON对象以使用RestSharp发布参数的项目,下面是我的代码:
var request = new RestRequest();
request.Method = Method.POST;
request.RequestFormat = DataFormat.Json;
request.AddBody(jsonObject);
return client.Execute<dynamic>(request);
Run Code Online (Sandbox Code Playgroud)
我意识到的是,不是将每个JSON名称值对添加为post参数,而是request.AddBody将整个JSON字符串添加为一个大的post参数.我的问题是,有没有办法让request.AddBody方法将每个JSON名称 - 值对添加为单独的帖子参数?我知道这request.AddParameter()可以完成工作但需要手动添加每个参数.
代替:
[0]:{
application/json="
{
"name":"john doe",
"age": "12",
"gender": "male"}
}
}
Run Code Online (Sandbox Code Playgroud)
期望的结果:
[0]:"name":"john doe"
[1]:"age":"12"
[2]:"gender":"male"
Run Code Online (Sandbox Code Playgroud) 最近更新的dotnet核心1.0.1到1.1和MVC中的ViewComponent开始失败,出现以下异常:
InvalidOperationException: One or more errors occurred. (The model item passed into the ViewDataDictionary is of type 'App.Models.HomeViewModel', but this ViewDataDictionary instance requires a model item of type 'App.Components.LoginViewComponent'.)
Run Code Online (Sandbox Code Playgroud)
该Index.cshtml呈现LoginViewComponent:
@model App.Models.HomeViewModel
<html>
@Component.InvokeAsync("LoginViewComponent")
</html>
Run Code Online (Sandbox Code Playgroud)
查看/主页/ Index.cshtml
ViewComponent LoginViewComponent/Default.cshtml只是一个显示模型信息的类:
@model App.Components.LoginViewCompoent
<body>
<div>@Html.DisplayFor(v=>v.LoginName)</div>
</body>
Run Code Online (Sandbox Code Playgroud)
查看/共享/组件/ LoginViewComponent/Default.cshtml
从Default.cshtml中删除@model指令时,它呈现正常.
是不是ViewComponent假设与包装它的父视图分开并且不可知?从异常看,似乎需要在HomeViewModel类中声明LoginViewComponent ViewComponent 才能呈现它.
在asp.net核心github上找不到任何关于此的更改说明.
对此的评论和帮助将不胜感激.
可能重复:
如何使用LINQ计算列表中的重复项
你知道如何计算linq中的副本.假设我有一个学生对象列表,我想找到一个名为'John'的学生数量?