• .NET字符串转JSON格式


    原JSON字符串

    {
        "errcode": 0, 
        "errmsg": "ok", 
        "process_instance": {
            "attached_process_instance_ids": [ ], 
            "biz_action": "NONE", 
            "business_id": "20210125000534484", 
            "create_time": "2021-01-25 16:39:53", 
            "form_component_values": [
                {
                    "component_type": "TableField", 
                    "ext_value": "{\"statValue\":[{\"id\":\"MoneyField-JQYS83D4\",\"label\":\"总报销金额(元)\",\"upper\":\"贰角伍分\",\"num\":\"0.25\"}],\"componentName\":\"TableField\"}", 
                    "id": "TableField-MINGXI", 
                    "name": "报销明细", 
                    "value": "[{\"rowValue\":[{\"componentType\":\"MoneyField\",\"label\":\"报销金额(元)\",\"extendValue\":\"{\\\"upper\\\":\\\"壹角贰分\\\",\\\"componentName\\\":\\\"MoneyField\\\"}\",\"value\":\"0.12\",\"key\":\"MoneyField-JQYS83D4\"},{\"componentType\":\"DepartmentField\",\"label\":\"费用所属小组\",\"extendValue\":[{\"number\":3,\"name\":\"事业部\",\"id\":\"1567735\"}],\"value\":\"事业部\",\"key\":\"DepartmentField_1F0JU5NK816O0\"},{\"componentType\":\"TextNote\",\"label\":\"说明\",\"value\":\"1、费用归属总部选行政中心本部。\\n5、外联部发生的费用,不能明确区分到下级巴的,费用归属选市场中心本部。\\n6、发生的费用涉及各个部门的(如年会费用),归属总部费用选行政中心本部。\",\"key\":\"TextNote_1XJOZAY9Z6N40\"},{\"componentType\":\"DDSelectField\",\"label\":\"报销类别\",\"extendValue\":{\"label\":\"办公费\",\"key\":\"option_K4JNCM0A\"},\"value\":\"办公费\",\"key\":\"DDSelectField-IZTK5BYV\"},{\"componentType\":\"DDSelectField\",\"label\":\"是否需要入库\",\"extendValue\":{\"label\":\"不需要入库(费用)\",\"key\":\"option_1\"},\"value\":\"不需要入库(费用)\",\"key\":\"DDSelectField-KBT1HP2U\"},{\"componentType\":\"TextareaField\",\"label\":\"费用明细\",\"value\":\"测试报销(勿批)测试报销(勿批)测试报销(勿批)测试报销(勿批)测试报销(勿批)测试报销(勿批)测试报销(勿批)\",\"key\":\"费用明细\"}]},{\"rowValue\":[{\"componentType\":\"MoneyField\",\"label\":\"报销金额(元)\",\"extendValue\":\"{\\\"upper\\\":\\\"壹角叁分\\\",\\\"componentName\\\":\\\"MoneyField\\\"}\",\"value\":\"0.13\",\"key\":\"MoneyField-JQYS83D4\"},{\"componentType\":\"DepartmentField\",\"label\":\"费用所属小组\",\"extendValue\":[{\"number\":2,\"name\":\"经营管理部\",\"id\":\"150926607\"}],\"value\":\"经营管理部\",\"key\":\"DepartmentField_1F0JU5NK816O0\"},{\"componentType\":\"TextNote\",\"label\":\"说明\",\"value\":\"1、归属总部费用选行政中心本部。\",\"key\":\"TextNote_1XJOZAY9Z6N40\"},{\"componentType\":\"DDSelectField\",\"label\":\"报销类别\",\"extendValue\":{\"label\":\"餐饮费\",\"key\":\"option_K4JNCM0H\"},\"value\":\"餐饮费\",\"key\":\"DDSelectField-IZTK5BYV\"},{\"componentType\":\"DDSelectField\",\"label\":\"是否需要入库\",\"extendValue\":{\"label\":\"不需要入库(费用)\",\"key\":\"option_1\"},\"value\":\"不需要入库(费用)\",\"key\":\"DDSelectField-KBT1HP2U\"},{\"componentType\":\"TextareaField\",\"label\":\"费用明细\",\"value\":\"测试报销(勿批)测试报销(勿批)测试报销(勿批)测试报销(勿批)测试报销(勿批)测试报销(勿批)测试报销(勿批)\",\"key\":\"费用明细\"}]}]"
                }, 
                {
                    "component_type": "DDSelectField", 
                    "ext_value": "{\"label\":\"总部\",\"key\":\"option_2\"}", 
                    "id": "DDSelectField_WBK6D86XC0", 
                    "name": "费用所属院区", 
                    "value": "总部"
                }
            ], 
            "operation_records": [
                {
                    "date": "2021-01-25 16:39:53", 
                    "operation_result": "NONE", 
                    "operation_type": "START_PRESS_INSTANCE", 
                    "userid": "24104569292501"
                }
            ], 
            "originator_dept_id": "1508735", 
            "originator_dept_name": "总部-经营中心-扩展事业部", 
            "originator_userid": "24104567501", 
            "result": "", 
            "status": "RUNNING", 
            "tasks": [
                {
                    "activity_id": "334d_43", 
                    "create_time": "2021-01-25 16:39:53", 
                    "task_result": "NONE", 
                    "task_status": "RUNNING", 
                    "taskid": "67206622", 
                    "url": "aflow.dingtalk.com?procInsId=578ba9-eb2c-4f9d-903b-0dc002038&taskId=672063722&businessId=20210125534484", 
                    "userid": "141547300126278817"
                }
            ], 
            "title": "***提交的集团报销"
        }, 
        "request_id": "8p3gj9629iq7"
    }

    字符串转JSON

    因为form_component_values里的详情返回的不是JSON格式,需要转义

    要提取报销金额,承担部门等

    string strcdbm = listValueVO[1].Value.ToString(); //承担部门编码(费用所属院区)
    
                        string strbxsm = listValueVO[0].Value;//报销说明.这个listValueVO[0]就是form_component_values节点
                        JArray jarry = (JArray)JsonConvert.DeserializeObject(strbxsm);
                        //JArray jarry = JArray.Parse(jo["rowValue"].ToString());
                        string thisid = "1";//分录ID
                        string parentId = business_id;//主表Id
    
                        for (var i02 = 0; i02 < jarry.Count; i02++)
                        {
                            JObject j = JObject.Parse(jarry[i02].ToString());
    
                            JArray jarry1 = JArray.Parse(j["rowValue"].ToString());
                            JObject jk0 = JObject.Parse(jarry1[0].ToString());//报销金额0.12
                            JObject jk1 = JObject.Parse(jarry1[1].ToString());//承担部门编码150867735
                            JObject jk3 = JObject.Parse(jarry1[3].ToString());//费用项目编码,名称办公费
    
                            string thisAmount = jk0["value"].ToString();//报销金额
                            string payDepart = jk1["extendValue"].ToString();//承担部门编码
                            payDepart = payDepart.Substring(payDepart.IndexOf("id")+2);
                            payDepart = payDepart.Replace("\"", "").Replace(":", "").Replace("}", "").Replace("]", "").Replace(" ", "");
                            string costItem = jk3["value"].ToString();//费用项目编码
                                                                      //for (var k = 0; k < jarry1.Count; k++)
                                                                      //{
                                                                      //    //JObject jk = JObject.Parse(jarry1[k].ToString());
                                                                      //}
                            string a03 = "";
                        }
    
                        string a02 = "";
  • 相关阅读:
    【Java学习系列】第3课--Java 高级教程
    【夯实PHP基础】nginx php-fpm 输出php错误日志
    【夯实Mysql基础】MySQL性能优化的21个最佳实践 和 mysql使用索引
    【架构设计】分布式文件系统 FastDFS的原理和安装使用
    【13】2016.12.13 周二--《小结2016》
    【诗词歌赋】2016.12.15 周四--文言鸿儒《年终的日常》
    【算法】(查找你附近的人) GeoHash核心原理解析及代码实现
    【夯实Nginx基础】Nginx工作原理和优化、漏洞
    【夯实PHP基础】PHP的反射机制
    HTML DOM简易学习笔记
  • 原文地址:https://www.cnblogs.com/wybshyy/p/16042529.html
Copyright © 2020-2023  润新知