neuecc / Utf8Json

Definitely Fastest and Zero Allocation JSON Serializer for C#(NET, .NET Core, Unity, Xamarin).
MIT License
2.36k stars 266 forks source link

Deserialize Array With Different Types #56

Open gitgutt opened 6 years ago

gitgutt commented 6 years ago

What's the best practice to deserialize the following json?

"name":"age children","attributes"=:[["27", "1", []],["28", "2", []]

Newtonsoft has the JsonArrayIndex attribute, which makes it easy to deal with it.

e.g. class Foo { public string Name; public DataValue Value; } class DataValue { [JsonArrayIndex(0)] public int Age; [JsonArrayIndex(1)] public int NumberOfChildren; }

Is manually parsing the array with a custom formatter the best way to do it with Utf8Json?

neuecc commented 6 years ago

Oh, I did not know JsonArrayIndex. Thanks. Yes, anyway currently the best way is make a custom formatter.