mgholam / fastJSON

Smallest, fastest polymorphic JSON serializer
https://www.codeproject.com/Articles/159450/fastJSON-Smallest-Fastest-Polymorphic-JSON-Seriali
MIT License
478 stars 148 forks source link

Why Multidimensional Arrays converted this way? #116

Open bqio opened 4 years ago

bqio commented 4 years ago
var circles = new Circle[]
{
  new Circle() { Center = new Point(0, 0), Radius = 1, data = new int [2, 3] { { 1, 2, 4 }, { 1, 2, 3 } } },
  new Circle() { Center = p, Radius = 2 },
  new Circle() { Center = p, Radius = 3 }
};

var json = JSON.ToNiceJSON(circles);
var data = JSON.ToObject<Circle[]>(json);
[
   {
      "Center" : {
         "X" : 0,
         "Y" : 0
      },
      "Radius" : 1,
      "data" : [
         1,
         2,
         4,
         1,
         2,
         3
      ]
   },
   {
      "Center" : {
         "X" : 0,
         "Y" : 1
      },
      "Radius" : 2,
      "data" : null
   },
   {
      "Center" : {
         "X" : 0,
         "Y" : 1
      },
      "Radius" : 3,
      "data" : null
   }
]

After the reverse transformation, data = int [6], but need int [2, 3].

mgholam commented 4 years ago

Probably a problem with serializing multi-dimensional arrays... I will look into it, thanks!

mgholam commented 4 years ago

The IEnumerable just goes though the list regardless, I have to use the Rank property. How is the following as an output :

"data" : [ [1,2,4] , [1,2,3] ],