обновление json parse
All checks were successful
Release / pack-and-publish (release) Successful in 45s

This commit is contained in:
FrigaT
2026-04-13 13:55:23 +03:00
parent a40b36ef96
commit 21a0c5abe6
10 changed files with 156 additions and 8 deletions

View File

@@ -0,0 +1,34 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace YandexMusic.API.Converters;
public class IntToStringConverter : JsonConverter<string>
{
public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Number)
{
// Пытаемся извлечь число как int или long
if (reader.TryGetInt32(out int intValue))
return intValue.ToString();
if (reader.TryGetInt64(out long longValue))
return longValue.ToString();
}
else if (reader.TokenType == JsonTokenType.String)
{
return reader.GetString();
}
else if (reader.TokenType == JsonTokenType.Null)
{
return null;
}
throw new JsonException($"Не удалось преобразовать {reader.TokenType} в строку.");
}
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
{
writer.WriteStringValue(value);
}
}