Я не понимаю, что делать с: system.text.json.jsonexception: «Значение json не может быть преобразовано в System.collectiC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Я не понимаю, что делать с: system.text.json.jsonexception: «Значение json не может быть преобразовано в System.collecti

Сообщение Anonymous »

Я пишу консольное приложение в C#, VS2022.
, где я получаю строку JSON от Orchestrator (UIPATH), попробуйте покинуть ее в Ienumerable. < /p>
i В течение всего дня все время прочитал все об этой ошибке, но я не могу понять, что я делаю неправильно, так что теперь я действительно хотел бы, чтобы кто -то помог мне или, по крайней мере, указал мне в правильном направлении.
Это строка: < /p>
{
"@odata.context": "https://xxxxx.com/odata/$metadata#Queue ... ngStatuses",
"@odata.count": 156,
"value": [
{
"ItemsToProcess": 1,
"ItemsInProgress": 0,
"QueueDefinitionId": 397,
"QueueDefinitionKey": "e5xxxxxx-xxxx-4c76-b145-f120d5de97dd",
"QueueDefinitionName": "_Framework2.0_TestQueue",
"QueueDefinitionDescription": null,
"QueueDefinitionAcceptAutomaticallyRetry": false,
"QueueDefinitionMaxNumberOfRetries": 0,
"QueueDefinitionEnforceUniqueReference": false,
"ProcessingMeanTime": 0,
"SuccessfulTransactionsNo": 0,
"ApplicationExceptionsNo": 0,
"BusinessExceptionsNo": 0,
"SuccessfulTransactionsProcessingTime": 0,
"ApplicationExceptionsProcessingTime": 0,
"BusinessExceptionsProcessingTime": 0,
"TotalNumberOfTransactions": 0,
"LastProcessed": "2022-03-01T08:42:10.11Z",
"ReleaseName": null,
"ReleaseId": null,
"IsProcessInCurrentFolder": null,
"SpecificDataJsonSchemaExists": false,
"OutputDataJsonSchemaExists": false,
"AnalyticsDataJsonSchemaExists": false,
"ProcessScheduleId": null,
"QueueFoldersCount": 1,
"Id": 397,
"Tags": []
}
]
}
< /code>
Это класс: < /p>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Text.Json;

namespace ConsoleApp1.Model
{

public class GetQueueStatusModel
{
[JsonPropertyName("@odata.context")]
public string? odatacontext { get; set; }

[JsonPropertyName("@odata.count")]
public int odatacount { get; set; }

public List? value { get; set; }
}

public class Value
{
public int ItemsToProcess { get; set; }
public int ItemsInProgress { get; set; }
public int QueueDefinitionId { get; set; }
public string? QueueDefinitionKey { get; set; }
public string? QueueDefinitionName { get; set; }
public object? QueueDefinitionDescription { get; set; }
public bool QueueDefinitionAcceptAutomaticallyRetry { get; set; }
public int QueueDefinitionMaxNumberOfRetries { get; set; }
public bool QueueDefinitionEnforceUniqueReference { get; set; }
public int ProcessingMeanTime { get; set; }
public int SuccessfulTransactionsNo { get; set; }
public int ApplicationExceptionsNo { get; set; }
public int BusinessExceptionsNo { get; set; }
public int SuccessfulTransactionsProcessingTime { get; set; }
public int ApplicationExceptionsProcessingTime { get; set; }
public int BusinessExceptionsProcessingTime { get; set; }
public int TotalNumberOfTransactions { get; set; }
public DateTime LastProcessed { get; set; }
public object? ReleaseName { get; set; }
public object? ReleaseId { get; set; }
public object? IsProcessInCurrentFolder { get; set; }
public bool SpecificDataJsonSchemaExists { get; set; }
public bool OutputDataJsonSchemaExists { get; set; }
public bool AnalyticsDataJsonSchemaExists { get; set; }
public object? ProcessScheduleId { get; set; }
public int QueueFoldersCount { get; set; }
public int Id { get; set; }
public List? Tags { get; set; }
}
}
< /code>
Вот где я пытаюсь его понизить: < /p>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApp1.Interfaces;
using ConsoleApp1.Model;
using System.Text.Json;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace ConsoleApp1.Repository
{
internal class GetQueueStatusRepository : IGetQueueStatusRepository
{
private readonly HttpClient _httpClient;

public GetQueueStatusRepository(HttpClient httpClient)
{
_httpClient = httpClient;
}

public async TaskGetQueueStatus()
{
var result = await _httpClient.GetAsync("odata/QueueProcessingRecords/UiPathODataSvc.RetrieveQueuesProcessingStatus");

result.EnsureSuccessStatusCode();

var response = await result.Content.ReadAsStringAsync();

return DeserializeResult(response);
}

private T? DeserializeResult(string json)
{
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
ReadCommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true
};

return JsonSerializer.Deserialize(json, options);
}

}
}
< /code>
Интерфейс: < /p>
using ConsoleApp1.Model;

namespace ConsoleApp1.Interfaces
{
internal interface IGetQueueStatusRepository
{
TaskGetQueueStatus();

}
}
< /code>
Я попробовал какой -нибудь конвертер для JSON, но я не мог заставить его работать для меня.
Alos попробовал некоторую регуляцию, чтобы редактировать строку, но без повезло. < /p>

Подробнее здесь: https://stackoverflow.com/questions/782 ... e-json-val
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»