我正在使用 System.Text.Json 包来使用序列化和反序列化。
当明确指定类型时,我可以将 json 字符串反序列化为对象,如下所示。
var data = JsonSerializer.Deserialize<PersonType>(jsonString);
Run Code Online (Sandbox Code Playgroud)
但动态类型不行。是否可以在不指定类型的情况下反序列化?谢谢你!
var data = JsonSerializer.Deserialize<dynamic>(jsonString);
Run Code Online (Sandbox Code Playgroud) 我有一个(字符串,十进制)字典,需要从第二个项目开始计算所有值(十进制值)的总和.使用LINQ可以实现吗?
我遇到了以下线程中列出的相同问题.
WSDL第一个WCF服务器,其中客户端不发送SOAPAction
我执行了同一个线程中列出的步骤(也显示在下面)
1)下载Microsoft WCF示例.从WF_WCF_Samples\WCF\Extensibility\Interop\RouteByBody\CS\service将以下文件添加到项目中
DispatchByBodyOperationSelector.cs
DispatchByBodyBehaviorAttribute.cs
2)将以下属性添加到您的界面(ServiceContract旁边)
XmlSerializerFormat
DispatchByBodyBehavior
Run Code Online (Sandbox Code Playgroud)
3)将以下内容添加到服务界面
[OperationContract(Action = "")]
public void DoNothing()
{
}
Run Code Online (Sandbox Code Playgroud)
4)对于我的服务,WrapperName和Wrappernamespace对于所有消息都为空.我不得不进入DispatchByBodyBehaviorAttribute并编辑ApplyDispatchBehavior()以添加以下行来检查:
if (qname.IsEmpty) {
qname = new XmlQualifiedName(operationDescription.Messages[0].Body.Parts[0].Name, operationDescription.Messages[0].Body.Parts[0].Namespace);
}
Run Code Online (Sandbox Code Playgroud)
现在,我收到一条错误消息"此消息无法支持该操作,因为它已被读取".我打开了跟踪并捕获了堆栈跟踪(下图).如果有人知道如何解决这个问题,我很感激您是否可以发表一些评论.谢谢你的帮助!
at System.ServiceModel.Channels.Message.GetReaderAtBodyContents()
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
at System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, …Run Code Online (Sandbox Code Playgroud) 我需要添加一些功能,以便能够打印datagridview中显示的内容.我试图使用位图类,但它似乎没有打印所有的行和列.它看起来像一个截图,缺少一些列和行.谁知道有更好的方法来处理这个问题?非常感谢.
我有一个具有多种复杂类型和简单类型的XSD(文件的一部分如下所示).我需要解析此文档以从复杂类型中引用的每个简单类型中获取maxLength.任何人都可以请求如何实现这一点?我需要以通用的方式实现它,所以如果我查询"Setup_Type",它应该给出以下输出.谢谢!
NewSetup/Amount = 12(元素标签的名称属性由"/"和嵌套的simpleType中的maxLength分隔)
NewSetup/Name = 50
<xsd:complexType name="Setup_Type">
<xsd:sequence>
<xsd:element name="NewSetup" type="NewSetup_Type" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="NewSetup_Type">
<xsd:sequence>
<xsd:element name="Amount" type="Amount_Type" minOccurs="1" maxOccurs="1" />
<xsd:element name="Name" type="Name_Type" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="Amount_Type">
<xsd:annotation>
<xsd:documentation>Amount</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="12" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="Name_Type">
<xsd:annotation>
<xsd:documentation>Name</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="50" />
</xsd:restriction>
</xsd:simpleType>
Run Code Online (Sandbox Code Playgroud) 我试图找出是否有办法从XmlReader计算文件大小.我没有在阅读器对象上看到任何有助于确定大小的内容.有任何想法吗?谢谢!
Using reader As Xml.XmlReader = GetXML(columnName.ToString())
End Using
Run Code Online (Sandbox Code Playgroud) 我需要从文件的当前路径向上导航一个文件夹,并在那里保存相同的文件.如何从目录路径中删除一个级别?谢谢!
C:\Users\stacy.zim\AppData\Local\Temp\ICLocal\e53486af-7e5e-4c54-b9dc-d15cb55f3f55.pdf
该文件将保存到下面.
C:\Users\stacy.zim\AppData\Local\Temp\e53486af-7e5e-4c54-b9dc-d15cb55f3f55.pdf
File.ReadAllBytes 在两次调用之间没有足够的调用间隔时会导致 IOException 吗?
当我设置网格的 Row 和 Col 时,它会触发 RowColChange 事件。RowColChange 有一些代码可以使用 File.ReadAllBytes 打开同一个文件。我知道 ReadAllBytes 内部在 FileStream 上使用 using 因此文件流在使用后关闭。但是在告诉操作系统文件被释放时是否可能有一些延迟,因此 File.ReadAllBytes 的后续使用可能会失败并引发异常。有什么想法吗?谢谢!
grid.Row = 0
grid.Row = 1
grid.Col = 3
Private Sub grid_RowColChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles grid.RowColChange
'Is it possible to get IOException saying the process can't access the file because it is being used by another process.
Display(File.ReadAllBytes(filePath))
End Sub
Run Code Online (Sandbox Code Playgroud) 如何在asp.net core MVC控制器中使用ReadAsStringAsync?Microsoft.AspNetCore.Mvc.Request 没有 Content 属性。有替代方案吗?谢谢你!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using AuthLibrary;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;
using System.Web.Http;
using System.Threading.Tasks;
[Microsoft.AspNetCore.Mvc.Route("TestAPI")]
public class TestController : Controller
{
[Microsoft.AspNetCore.Mvc.HttpPost]
[AllowAnonymous]
[Microsoft.AspNetCore.Mvc.Route("Start")]
public async Task<HttpResponseMessage> Start()
{
string req = await this.Request.Content.ReadAsStringAsync();
////
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试实现一个带有允许多项选择的复选框的下拉列表。选择后,多个选择将显示为逗号分隔列表。是否有任何内置控件可以在 razor 页面中使用。我查看了 html 选择控件、MatCheckBox 控件,但它们似乎没有这种外观。感谢您的任何建议!
c# ×6
.net ×2
vb.net ×2
.net-3.5 ×1
asp.net-core ×1
blazor ×1
c#-3.0 ×1
c#-4.0 ×1
linq ×1
razor-pages ×1
wcf ×1
wcf-binding ×1
xsd ×1