C# 检测传入的json格式是否符合标准,对比json是否一样

/// <summary>
        /// 检测传入的json格式是否符合标准
        /// </summary>
        /// <param name="inobj">传入的json</param>
        /// <param name="obj">标准json</param>
        /// <param name="fathername"></param>
        /// <returns></returns>
        public static string ComparePropertiesJ(JObject inobj, JObject obj, string ordertype, string fathername = "")
        {
            //为空判断
            if (inobj == null)
                return "数据不可以为空";

            //根据开关删减标准json的字段
            if (ordertype == td)
            {
                if (GetSystem_tb("IsNoFabricEnter")) //查询开关
                    obj.Remove("fabric");
            }
            else if (ordertype == dh)
            {
                if (GetSystem_tb("IsNoModelEnter"))//查询开关
                    obj.Remove("sty
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用下面的代码来实现C#中的POST请求传递数组类型的body,使用Newtonsoft.Json进行序列化和反序列化: ```csharp using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Text; public class Program { static void Main(string[] args) { // 定义POST请求的URL地址 string url = "http://example.com/api/test"; // 定义POST请求的Body参数,这里使用List<string>类型的数组 List<string> data = new List<string>() { "value1", "value2", "value3" }; // 将List<string>类型的数组转换为JSON格式的字符串 string jsonData = JsonConvert.SerializeObject(data); // 设置POST请求的Header参数 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/json"; // 将JSON格式的字符串转换为Byte数组 byte[] byteData = Encoding.UTF8.GetBytes(jsonData); // 设置POST请求的Body参数 request.ContentLength = byteData.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(byteData, 0, byteData.Length); requestStream.Close(); // 发送POST请求并接收响应 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); string responseText = reader.ReadToEnd(); Console.WriteLine(responseText); reader.Close(); responseStream.Close(); response.Close(); } } ``` 在上面的代码中,我们定义了一个List<string>类型的数组,然后使用Newtonsoft.Json将其转换为JSON格式的字符串。接着,我们设置了POST请求的Header参数,包括请求的方法、请求的Content-Type和请求的Body参数。最后,我们发送POST请求并接收响应,将响应输出到控制台上。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值