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; }
    }


}
相关推荐
APIshop1 小时前
Java 实战:调用 item_search_tmall 按关键词搜索天猫商品
java·开发语言·数据库
血小板要健康2 小时前
Java基础常见面试题复习合集1
java·开发语言·经验分享·笔记·面试·学习方法
淼淼7632 小时前
安装jdk1.8
java·开发语言
PfCoder2 小时前
WinForm真入门(23)---PictureBox 控件详细用法
开发语言·windows·c#·winform
Legendary_0082 小时前
Type-C 一拖二快充线:突破单口限制的技术逻辑
c语言·开发语言
过期动态2 小时前
Java开发中的@EnableWebMvc注解和WebMvcConfigurer接口
java·开发语言·spring boot·spring·tomcat·maven·idea
csbysj20203 小时前
Web 标准
开发语言
老姚---老姚3 小时前
在windows下编译go语言编写的dll库
开发语言·windows·golang
diediedei3 小时前
模板编译期类型检查
开发语言·c++·算法
穿过锁扣的风3 小时前
零基础入门 Python 爬虫:从基础到实战,爬取虎扑 / 豆瓣 / 图片全掌握
开发语言·爬虫·python