From 233ed3a961025fa5bddbcc437a9f300f5467923a Mon Sep 17 00:00:00 2001 From: Jacky <66659162+Perpete@users.noreply.github.com> Date: Thu, 28 Oct 2021 17:58:22 +0200 Subject: [PATCH] Correction for arrays of more than 2 dimensions When using the type interpretation for arrays of more than 2 dimensions, on deserialization, an error is encountered. There is a problem in the switch case that does not allow adding more than one comma between the brackets of System.xxxx []. View issue #2591 --- Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs index 5e09de1e..ad7d7a43 100644 --- a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs @@ -187,19 +187,30 @@ namespace Newtonsoft.Json.Utilities // loop through the type name and filter out qualified assembly details from nested type names bool writingAssemblyName = false; bool skippingAssemblyDetails = false; + bool DimensionArrayMaybe = false; for (int i = 0; i < fullyQualifiedTypeName.Length; i++) { char current = fullyQualifiedTypeName[i]; switch (current) { case '[': + writingAssemblyName = false; + skippingAssemblyDetails = false; + DimensionArrayMaybe = true; + builder.Append(current); + break; case ']': writingAssemblyName = false; skippingAssemblyDetails = false; + DimensionArrayMaybe = false; builder.Append(current); break; case ',': - if (!writingAssemblyName) + if (DimensionArrayMaybe) + { + builder.Append(current); + } + else if (!writingAssemblyName) { writingAssemblyName = true; builder.Append(current); @@ -210,6 +221,7 @@ namespace Newtonsoft.Json.Utilities } break; default: + DimensionArrayMaybe = false; if (!skippingAssemblyDetails) { builder.Append(current); @@ -1093,4 +1105,4 @@ namespace Newtonsoft.Json.Utilities return Activator.CreateInstance(type); } } -} \ No newline at end of file +}