C# json解析demo

csharp 复制代码
using Newtonsoft.Json;
using System;
using System.Collections.Generic;


namespace ConsoleApp2
{
    public class Program
    {

        public static ResponseModel ReceiveData(string json)
        {
            return JsonConvert.DeserializeObject<ResponseModel>(json);
        }

        static void Main(string[] args)
        {
            string res =
                "{\"ResCode\":0,\"Msg\":\"测量完成\",\"Command\":\"meas&number=20200118&expo=white&blackmura=true\",\"Content\":{\"Min\":{\"Value\":52.1971855,\"Cx\":0.0,\"Cy\":1.0},\"Max\":{\"Value\":368.038177,\"Cx\":0.0,\"Cy\":1.0},\"Average\":\"241.07\",\"Uniform\":\"0.142\",\"BlackMuraData\":{\"Num\":[\"1.1\"],\"Testingtime\":[\"2024-09-18 18:44:13\"],\"BlackMura\":[\"0.0349201045608842\"],\"Pass/Fail\":[\"false\"],\"MaxLuminance\":[\"233.066680908203\"],\"MinLuminance\":[\"213.866683959961\"],\"LuminanceAvg\":[\"223.466682434082\"],\"MaxGradient\":[\"3.88060212135315\"],\"Uniformity\":[\"91.7620155427517\"]}}}";


            try
            {
                ResponseModel result = ReceiveData(res);
                foreach (var item in result.Content.BlackMuraData)
                {
                    Console.WriteLine($"{ item.Key } :{ item.Value.First()} ");
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine($"数据解析失败:{ex.Message}");
            }

        }
    }

    public class ResponseModel
    {
        public int ResCode { get; set; }
        public string Msg { get; set; }
        public ContentModel Content { get; set; }
    }

    public class ContentModel
    {
        public MinModel Min { get; set; }
        public MaxModel Max { get; set; }
        public double Average { get; set; }
        public double Uniform { get; set; }
        public Dictionary<string, List<string>> BlackMuraData { get; set; }
    }

    public class MinModel
    {
        public double Value { get; set; }
        public double Cx { get; set; }
        public double Cy { get; set; }
    }

    public class MaxModel
    {
        public double Value { get; set; }
        public double Cx { get; set; }
        public double Cy { get; set; }
    }


}
相关推荐
土了个豆子的1 分钟前
02.继承MonoBehaviour的单例模式基类
开发语言·visualstudio·单例模式·c#·里氏替换原则
疯狂的维修2 分钟前
c#中public类比博图
c#·自动化
qq_172805598 分钟前
Go 自建库的使用教程与测试
开发语言·后端·golang
久绊A14 分钟前
Hydra-SSH 破解安全防范
开发语言·php
阿昭L21 分钟前
c++中获取随机数
开发语言·c++
3壹27 分钟前
数据结构精讲:栈与队列实战指南
c语言·开发语言·数据结构·c++·算法
悟乙己36 分钟前
使用 Python 中的强化学习最大化简单 RAG 性能
开发语言·python·agent·rag·n8n
max50060040 分钟前
图像处理:实现多图点重叠效果
开发语言·图像处理·人工智能·python·深度学习·音视频
RickyWasYoung1 小时前
【代码】matlab-遗传算法工具箱
开发语言·matlab
土了个豆子的3 小时前
03.缓存池
开发语言·前端·缓存·visualstudio·c#