Json 的扁平化和非扁平化是什么意思?我们还可以使用 ObjectMapper class 来反序列化扁平化的 json 属性吗?
What is meant by Flattening and Unflattening of Json? Also can we use ObjectMapper class to deserialize a flattened json attribute?
我想了解压平 Json 和解压 Json 到底是什么。任何链接或博客都会有所帮助。
另外 w.r.t 另一个问题,我正在尝试将扁平化的 json 属性反序列化为 objectmapper 对象。我正在尝试的 Json 格式如下。
{
"MyUserID": "45345dfsf4545",
"attributes": {
"ArrayAttribute1[0].alertMessage": "You have consumed all of your data allowance",
"ArrayAttribute1[0].promoName": "MyPromoTest",
"ArrayAttribute2[0].showmorepromosbutton": "true",
"ArrayAttribute1[0].promoPrice": "P 149.00",
"userType": 1,
"Attribute1": "Jan 28 2016 . 3:09PM",
"Attribute1": "true",
"Attribute2.validityColor": "RED",
"Attribute2.subscriberBal": "P 29.5",
}
}
找到这个存储库 (https://github.com/wnameless/json-flattener) 来展平和展平 json。在将其提供给 ObjectMapper 之前,请确保先将其展开为字符串。遗憾的是没有找到定义差异的规范。
扁平化意味着将 JSON 对象放入类似单层次结构的结构中,也称为扁平结构,即没有子对象或父对象,一切都是键值对.点运算符可以访问嵌套对象。
相反,Un-flattening是指将扁平化后的结构放到存在父子结构的多级结构中。
您需要将未展平的结构传递给 Object-mapper 以对其进行反序列化。
以下示例将有助于更好地理解它
嵌套JSON对象
{ "a":
{ "b": 1,
"c": null,
"d": [false, true]
},
"e": "f",
"g": 2.3
}
扁平化JSON
{ "a.b": 1,
"a.c": null,
"a.d[0]": false,
"a.d[1]": true,
"e": "f",
"g": 2.3
}
Java 地图像被压扁了JSON
{a.b=1, a.c=null, a.d[0]=false, a.d[1]=true, e=f, g=2.3}
为什么需要展平?
如果你没有 JSON 对象的内部结构,那么访问内部的所有元素将非常麻烦,因此简单的解决方案是将所有内容放在同一级别,对象的深度由点运算符描述。
所以扁平化可以更容易地访问内部元素。
序列化和反序列化只能在非扁平化 JSONs 上发生。
我想了解压平 Json 和解压 Json 到底是什么。任何链接或博客都会有所帮助。
另外 w.r.t 另一个问题,我正在尝试将扁平化的 json 属性反序列化为 objectmapper 对象。我正在尝试的 Json 格式如下。
{
"MyUserID": "45345dfsf4545",
"attributes": {
"ArrayAttribute1[0].alertMessage": "You have consumed all of your data allowance",
"ArrayAttribute1[0].promoName": "MyPromoTest",
"ArrayAttribute2[0].showmorepromosbutton": "true",
"ArrayAttribute1[0].promoPrice": "P 149.00",
"userType": 1,
"Attribute1": "Jan 28 2016 . 3:09PM",
"Attribute1": "true",
"Attribute2.validityColor": "RED",
"Attribute2.subscriberBal": "P 29.5",
}
}
找到这个存储库 (https://github.com/wnameless/json-flattener) 来展平和展平 json。在将其提供给 ObjectMapper 之前,请确保先将其展开为字符串。遗憾的是没有找到定义差异的规范。
扁平化意味着将 JSON 对象放入类似单层次结构的结构中,也称为扁平结构,即没有子对象或父对象,一切都是键值对.点运算符可以访问嵌套对象。 相反,Un-flattening是指将扁平化后的结构放到存在父子结构的多级结构中。
您需要将未展平的结构传递给 Object-mapper 以对其进行反序列化。
以下示例将有助于更好地理解它
嵌套JSON对象
{ "a":
{ "b": 1,
"c": null,
"d": [false, true]
},
"e": "f",
"g": 2.3
}
扁平化JSON
{ "a.b": 1,
"a.c": null,
"a.d[0]": false,
"a.d[1]": true,
"e": "f",
"g": 2.3
}
Java 地图像被压扁了JSON
{a.b=1, a.c=null, a.d[0]=false, a.d[1]=true, e=f, g=2.3}
为什么需要展平? 如果你没有 JSON 对象的内部结构,那么访问内部的所有元素将非常麻烦,因此简单的解决方案是将所有内容放在同一级别,对象的深度由点运算符描述。 所以扁平化可以更容易地访问内部元素。
序列化和反序列化只能在非扁平化 JSONs 上发生。