How do I read a section in JSON result by httpClient?

问题描述 投票:0回答:0

这是检索 JSON 的 C# 代码:

try
        {
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Accept.Clear();
            client.BaseAddress = new Uri(_serviceConfig.DataGapsBaseUrl);
            var request = new HttpRequestMessage(HttpMethod.Get, "/piper/jobs/" + jobId.ToString() + "/status");

            var token = await GetToken();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            var response = await client.SendAsync(request);
            var result = await response.Content.ReadAsStringAsync();
            var info = JObject.Parse(result);
            return true;
        }

如何提取返回的 JSON 中的这个特定部分(以黄色突出显示)? Dfid 是该记录的唯一 ID。

{
"outputs": {},
"execution": [
    {
        "jobId": "8871d0ca0f324aae9685f768b00eddfb",
        "createTime": "2023-04-02T21:49:34.913+0000",
        "name": "dependency tasks",
        "startTime": "2023-04-02T21:49:34.934+0000",
        "id": "ae3d668f2bef4e5ca9ae262159b271ad",
        "label": "dependency tasks",
        "taskNumber": 1,
        "type": "dependency",
        "priority": 0,
        "tasks": [
            {
                "dfId": "ad2bb0db-402a-47f6-928d-3fe4276ee417",
                "name": "df_TCparamtest_alternateid_value_mapping_not_type_DOBAl_175234",
                "type": "runDataFlow",
                "label": "Data",
                "userId": 17,
                "livyServer": 101,
                "parameters": "{\"limit_rows\":\"limit 2000\",\"Run_Id\":\"\",\"Batch_Id\":\"4229223\"}",
                "stopOnTaskFailure": "N",
                "stopDependentTasks": "N"
            }
        ],
        "status": "COMPLETED"
    },
    {
        "stopOnTaskFailure": "N",
        "label": "Data",
        "stopDependentTasks": "N",
        "type": "runDataFlow",
        "priority": 0,
        "userId": 17,
        "parentId": "ae3d668f2bef4e5ca9ae262159b271ad",
        "output": "{\"status\":\"Completed\",\"message\":[{\"name\":\"Transform_out\",\"status\":\"Completed\",\"message\":\"Transform_out executed successfully and processed 0 rows\"},{\"name\":\"Data_compare_unformattednumber\",\"status\":\"Completed\",\"message\":\"Data_compare_unformattednumber executed successfully. The Details are :  Duplicates In A : 0  Duplicates In B : 0  Only In A : 0  Only In B : 0  Difference : 0  Matched : 0 \"},{\"name\":\"startComponent\",\"status\":\"Completed\",\"message\":\"Component executed successfully\"},{\"name\":\"Transform_in\",\"status\":\"Completed\",\"message\":\"Transform_in executed successfully and processed 0 rows\"}],\"runId\":2863}",
        "executionTime": 87765,
        "jobId": "8871d0ca0f324aae9685f768b00eddfb",
        "livyServer": 101,
        "dfId": "ad2bb0db-402a-47f6-928d-3fe4276ee417",
        "createTime": "2023-04-02T21:49:34.924+0000",
        "name": "df_TCparamtest_alternateid_value_mapping_not_type_DOBAl_175234",
        "progress": 100,
        "startTime": "2023-04-02T21:49:34.927+0000",
        "id": "f38cf10e30a54c1694d32413a7d53689",
        "endTime": "2023-04-02T21:51:02.693+0000",
        "parameters": "{\"limit_rows\":\"limit 2000\",\"Run_Id\":\"\",\"Batch_Id\":\"4229223\"}",
        "status": "COMPLETED"
    }
],
"inputs": {
    "Batch_Id": 4229223
},
"currentTask": -1,
"label": "Pipeline",
"priority": 0,
"pipelineId": "5b51b5ba2af142c4b10a68db35f2dd18",
"createTime": "2023-04-02T21:49:34.892+0000",
"webhooks": [],
"startTime": "2023-04-02T21:49:34.900+0000",
"id": "8871d0ca0f324aae9685f768b00eddfb",
"endTime": "2023-04-02T21:51:02.717+0000",
"status": "COMPLETED"

}

c# json httpclient httpresponse
© www.soinside.com 2019 - 2024. All rights reserved.