Array of objects vs Object of Objects

后端 未结 6 1089
有刺的猬
有刺的猬 2020-12-13 05:56

The issue is to decided the trade offs between following notations:

JSON based:

\"users\": {
    \"id1\": {
        \"id\": \"id1\",         


        
6条回答
  •  执笔经年
    2020-12-13 06:16

    One big disadvantage of your first "JSON based" notation that comes to mind is that some frameworks will have problems with (de)serialization of this. For example the DataContractSerializer (C# .NET) will expect the fields id1 and id2 to be defined (hardcoded) in the class of your objects users. I'm not sure if this applies to some Java frameworks, too. Maybe the framework will you use can deserialze it as a HashMap instead.

    Altogether I'd find the array notation much more intuitive to work with when it comes to iteration etc.

提交回复
热议问题