• 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();
            }
    

      

  • 相关阅读:
    Percona: How to Restore MySQL Logical Backup at Maximum Speed
    MySQL之UNDO及MVCC、崩溃恢复
    MySQL checkpoint深入分析
    关于MySQL latch争用深入分析与判断
    InnoDB关键特性之刷新邻接页-异步IO
    InnoDB关键特性之自适应hash索引
    MySQL后台线程的清理工作
    MySQL IO线程及相关参数调优
    MySQL存储写入性能严重抖动分析
    MySQL的SQL预处理(Prepared)
  • 原文地址:https://www.cnblogs.com/alinh/p/10083014.html
Copyright © 2020-2023  润新知