C# 获取Newtonsoft.Json的JObject多层节点内容

json形如(企业微信审核接口返回结果)

{
    "errcode": 0,
    "errmsg": "ok. Warning: wrong json format. ",
    "info": {
        "sp_no": "202011300016",
        "sp_name": "请假",
        "sp_status": 2,
        "template_id": "xxxxxxxxxxxxxxxxx",
        "apply_time": 1606703944,
        "applyer": {
            "userid": "Z2019-018",
            "partyid": "10"
        },
        "sp_record": [{
            "sp_status": 2,
            "approverattr": 1,
            "details": [{
                "approver": {
                    "userid": "Z2019-509"
                },
                "speech": "",
                "sp_status": 2,
                "sptime": 1606704031,
                "media_id": []
            }, {
                "approver": {
                    "userid": "Z2019-043"
                },
                "speech": "",
                "sp_status": 1,
                "sptime": 0,
                "media_id": []
            }]
        }, {
            "sp_status": 2,
            "approverattr": 1,
            "details": [{
                "approver": {
                    "userid": "Z2018-054"
                },
                "speech": "",
                "sp_status": 2,
                "sptime": 1606704117,
                "media_id": []
            }]
        }],
        "notifyer": [{
            "userid": "Z2017-421"
        }, {
            "userid": "Z2019-018"
        }],
        "apply_data": {
            "contents": [{
                "control": "Vacation",
                "id": "vacation-1563793073xxx",
                "title": [{
                    "text": "请假类型",
                    "lang": "zh_CN"
                }, {
                    "text": "Leave Type",
                    "lang": "en"
                }],
                "value": {
                    "tips": [],
                    "members": [],
                    "departments": [],
                    "files": [],
                    "children": [],
                    "stat_field": [],
                    "vacation": {
                        "selector": {
                            "type": "single",
                            "options": [{
                                "key": "9",
                                "value": [{
                                    "text": "事假",
                                    "lang": "zh_CN"
                                }]
                            }]
                        },
                        "attendance": {
                            "date_range": {
                                "type": "hour",
                                "new_begin": 1606780800,
                                "new_end": 1606899600,
                                "new_duration": 57600
                            },
                            "type": 1,
                            "slice_info": {
                                "day_items": [{
                                    "daytime": 1606752000,
                                    "time_sections": [],
                                    "duration": 28800
                                }, {
                                    "daytime": 1606838400,
                                    "time_sections": [],
                                    "duration": 28800
                                }],
                                "duration": 57600
                            }
                        }
                    },
                    "sum_field": [],
                    "related_approval": [],
                    "students": [],
                    "classes": []
                }
            }, {
                "control": "Textarea",
                "id": "item-14975813xxx01",
                "title": [{
                    "text": "请假事由",
                    "lang": "zh_CN"
                }, {
                    "text": "Leave Reason",
                    "lang": "en"
                }],
                "value": {
                    "text": "家里有事",
                    "tips": [],
                    "members": [],
                    "departments": [],
                    "files": [],
                    "children": [],
                    "stat_field": [],
                    "sum_field": [],
                    "related_approval": [],
                    "students": [],
                    "classes": []
                }
            }, {
                "control": "Text",
                "id": "Text-15908100xxx",
                "title": [{
                    "text": "备注",
                    "lang": "zh_CN"
                }],
                "value": {
                    "text": "无",
                    "tips": [],
                    "members": [],
                    "departments": [],
                    "files": [],
                    "children": [],
                    "stat_field": [],
                    "sum_field": [],
                    "related_approval": [],
                    "students": [],
                    "classes": []
                }
            }, {
                "control": "File",
                "id": "item-1497581426xxx",
                "title": [{
                    "text": "说明附件",
                    "lang": "zh_CN"
                }, {
                    "text": "Attachment",
                    "lang": "en"
                }],
                "value": {
                    "tips": [],
                    "members": [],
                    "departments": [],
                    "files": [],
                    "children": [],
                    "stat_field": [],
                    "sum_field": [],
                    "related_approval": [],
                    "students": [],
                    "classes": []
                }
            }]
        },
        "comments": []
    }
}

 

JObject json1 = (JObject)JsonConvert.DeserializeObject(data);//data上述返回结果

JArray array = (JArray)(json1["info"]["apply_data"]["contents"]);//数组

foreach (var jObject in array)

{

  //取数据

}

参考于:https://www.cnblogs.com/cwr-toki/p/10092089.html

 

上一篇:Json数组,Newtonsoft.Json应用


下一篇:Newtonsoft.Json忽略DataContract特性