我正在尝试将发送给邮递员的XML正文转换为蛇形情况下的Json。 有人可以帮我将JSON响应消息转换为蛇形案例。 到目前为止,我有以下代码:
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
DefaultContractResolver contractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
};
if (req.ContentType.IndexOf(@"/xml", 0, System.StringComparison.OrdinalIgnoreCase) == -1)
{
return new BadRequestObjectResult(@"Content-Type header must be an XML content type");
}
XmlDocument doc = new XmlDocument();
doc.Load(req.Body);
doc.RemoveChild(doc.FirstChild);
string json = JsonConvert.SerializeObject(doc, new JsonSerializerSettings
{
ContractResolver = contractResolver,
Formatting = Newtonsoft.Json.Formatting.Indented
});
return new OkObjectResult(json);