Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
扁平化json的优点和缺点是什么?_Json_Performance_Flatten - Fatal编程技术网

扁平化json的优点和缺点是什么?

扁平化json的优点和缺点是什么?,json,performance,flatten,Json,Performance,Flatten,我目前正在为我的项目设计json api。我在互联网上搜索过,发现json几乎有两种风格。一个是 { "user":{ "id":12, "name":"Jack", "address":{ "city":"New York", "post":"123456" } } } 另一种是: { "user.id":12, "user.name":"Jack"

我目前正在为我的项目设计json api。我在互联网上搜索过,发现json几乎有两种风格。一个是

{
    "user":{
        "id":12,
        "name":"Jack",
        "address":{
            "city":"New York",
            "post":"123456"
        }
    }
}
另一种是:

{
    "user.id":12,
    "user.name":"Jack",
    "user.address.city":"New York",
    "user.address.post":"123456"
}
我认为第一个是可以的,但既然第二个出现了,那一定是有原因的。所以我想知道两种格式之间的差异,尤其是性能差异。我在谷歌、stackoverflow和其他一些网站上搜索过,想找到答案。但我没有特别的。当然,显示了一些有用的信息,但仍然没有性能比较。
如果有人有好的答案,我将不胜感激

一个明显的问题是空间使用,特别是在具有深树的大小合适的json对象中。您的意思是,扁平化的json对象需要更多的空间,因为冗余使用了“父键”?是的(尽管您可能已经知道了),谢谢。那么,将java对象转换为普通json格式和扁平化格式之间的性能差异又如何呢?扁平化版本通常不会更快(因为大小),但它是否会产生任何实际/明显的差异取决于此json是什么。