mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
fix: properly serialize JSON arrays and objects in search3 response
This commit is contained in:
@@ -536,19 +536,27 @@ public class SubsonicController : ControllerBase
|
|||||||
var dict = new Dictionary<string, object>();
|
var dict = new Dictionary<string, object>();
|
||||||
foreach (var prop in element.EnumerateObject())
|
foreach (var prop in element.EnumerateObject())
|
||||||
{
|
{
|
||||||
dict[prop.Name] = prop.Value.ValueKind switch
|
dict[prop.Name] = ConvertJsonValue(prop.Value);
|
||||||
{
|
|
||||||
JsonValueKind.String => prop.Value.GetString() ?? "",
|
|
||||||
JsonValueKind.Number => prop.Value.TryGetInt32(out var i) ? i : prop.Value.GetDouble(),
|
|
||||||
JsonValueKind.True => true,
|
|
||||||
JsonValueKind.False => false,
|
|
||||||
_ => prop.Value.ToString()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
dict["isExternal"] = !isLocal;
|
dict["isExternal"] = !isLocal;
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private object ConvertJsonValue(JsonElement value)
|
||||||
|
{
|
||||||
|
return value.ValueKind switch
|
||||||
|
{
|
||||||
|
JsonValueKind.String => value.GetString() ?? "",
|
||||||
|
JsonValueKind.Number => value.TryGetInt32(out var i) ? i : value.GetDouble(),
|
||||||
|
JsonValueKind.True => true,
|
||||||
|
JsonValueKind.False => false,
|
||||||
|
JsonValueKind.Array => value.EnumerateArray().Select(ConvertJsonValue).ToList(),
|
||||||
|
JsonValueKind.Object => value.EnumerateObject().ToDictionary(p => p.Name, p => ConvertJsonValue(p.Value)),
|
||||||
|
JsonValueKind.Null => null!,
|
||||||
|
_ => value.ToString()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private XElement ConvertSubsonicXmlElement(XElement element, string type)
|
private XElement ConvertSubsonicXmlElement(XElement element, string type)
|
||||||
{
|
{
|
||||||
var newElement = new XElement(element);
|
var newElement = new XElement(element);
|
||||||
|
|||||||
Reference in New Issue
Block a user