我在使用 json_insert 函数插入时遇到 json 键排序问题。
我有如下排序的记录
“航空”、“航空 express ”
“CFR”、“成本加运费”
“FH”、“自由屋”
"联合国"、"联合国"
“UPS”、“联合包裹服务”
使用 json_insert 函数将上述记录转换为 json 后,我看到的结果如下
{"FH":"Free house", "UN": "United Nations", "AIR": "AIR Express", "CFR": "Cost and Freight", "UPS": "United Parcel Service"
但我希望 json 按照我插入的顺序维护 key 。虽然我可以感觉到它正在尝试根据键的字符长度来维护顺序。但是我怎样才能摆脱让键按顺序对齐。
最佳答案
这很可悲,但目前无法保持原始 key 顺序。
Normalization, Merging, and Autowrapping of JSON Values
The normalization performed by MySQL also sorts the keys of a JSON object (for the purpose of making lookups more efficient). The result of this ordering is subject to change and not guaranteed to be consistent across releases. In addition, extra whitespace between keys, values, or elements in the original document is discarded.
关于json - Mysql 5.7 原生 json 支持 - 在 json_insert 函数中控制键顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56146086/