zoukankan      html  css  js  c++  java
  • C# 中对于json的解析小结

    1、解析之前的json格式

    [{
    		"Name": "冯111",
    		"PID": "130627199202283306",
    		"Jbyanglaobx": "100",
    		"Jbyiliaobx": "200",
    		"Sybx": "300",
    		"Zfgjj": "400",
    		"Nj": "500"
    	},
    	{
    		"Name": "冯333",
    		"PID": "130627199202283307",
    		"Jbyanglaobx": "200",
    		"Jbyiliaobx": "300",
    		"Sybx": "400",
    		"Zfgjj": "500",
    		"Nj": "600"
    	}
    ]
    

      2、解析之后的json格式为

    {
    	"whichPeriod": "201812",
    	"data": [{
    			"identificationNumber": "130627199202283306",
    			"name": "冯111",
    			"endowmentInsurance": "100",
    			"medicalinsurance": "200",
    			"insurancePremium": "300",
    			"housingFund": "400",
    			"annuity": "500"
    		},
    		{
    			"identificationNumber": "130627199202283307",
    			"name": "冯333",
    			"endowmentInsurance": "200",
    			"medicalinsurance": "300",
    			"insurancePremium": "400",
    			"housingFund": "500",
    			"annuity": "600"
    		}
    	]
    }
    

      方法为

    private string parseJson(string para, string sbmonth)
            {
                JArray jarryOut = new JArray();
                JObject json = new JObject();
                
                json.Add("whichPeriod", sbmonth);
                JArray jarry = (JArray)JsonConvert.DeserializeObject(para, GlobalInfo.GetInstance().jsonSetting);
                for(int i=0; i<jarry.Count; i++)
                {
                    JObject jsonData = new JObject();
                    string dataContent = JsonHelper.ParseJsonArrayValue(para, i);               
                    jsonData.Add("identificationNumber", JsonHelper.ParseJsonValue(dataContent, "PID"));
                    jsonData.Add("name", JsonHelper.ParseJsonValue(dataContent, "Name"));
                    jsonData.Add("endowmentInsurance", JsonHelper.ParseJsonValue(dataContent, "Jbyanglaobx"));
                    jsonData.Add("medicalinsurance", JsonHelper.ParseJsonValue(dataContent, "Jbyiliaobx"));
                    jsonData.Add("insurancePremium", JsonHelper.ParseJsonValue(dataContent, "Sybx"));
                    jsonData.Add("housingFund", JsonHelper.ParseJsonValue(dataContent, "Zfgjj"));
                    jsonData.Add("annuity", JsonHelper.ParseJsonValue(dataContent, "Nj"));
                    jarryOut.Add(jsonData);                            
                }
                json.Add("data", jarryOut);
                return json.ToString();
            }
    

      

  • 相关阅读:
    ABP初始化
    ABP生成错误:必须添加对程序集“netstandard”的引用
    树莓派安装Mysql
    多对多关系的中间表命名
    dapper.net 存储过程
    Rabbitmq发送方消息确认
    Rabbitmq发送消息Message的两种写法
    ThreadLocal原理
    多模块打包为可执行jar问题
    类中属性加载顺序的demo
  • 原文地址:https://www.cnblogs.com/alinh/p/10083014.html
Copyright © 2011-2022 走看看