如何使用字节顺序按字典顺序对结构重新排序?
使用 API 进行开发,我在 ColdFusion 中有一个结构。我需要使用字节顺序按字典顺序对结构重新排序。
“按名称字典顺序对参数进行排序 [原文如此](字节排序,标准排序,不自然或不区分大小写)。如果参数具有相同的名称,则按值排序。”
采用 ColdFusion 9 中的结构,如何重新排序以符合上述要求? JAVA 库?
谢谢
Developing with an API, I have a structure in ColdFusion. I need to re-sort the structure using byte ordering lexicographically.
"Sort the parameters by name lexicographically [sic] (byte ordering, the standard sorting, not natural or case insensitive). If the parameters have the same name, then sort by the value."
Taking a structure in ColdFusion 9, how can I reorder it to comply with the above? JAVA Lib?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将把这个作为一个单独的答案发布,因为我相信我的第一个答案是不正确的......让我们尝试这个:
这会给你一个按字典顺序排序的键数组,忽略所有大小写。
StructSort
函数根据键值而不是键名称进行排序。I'm going to post this as a separate answer, because I believe my first one is incorrect... Let's try this one instead:
That will give you an array of keys sorted lexicographically, ignoring all casing. The
StructSort
function was sorting on the key values, not the key names.抱歉我的困惑,但是字典排序和自然排序(至少对于 Java 字符串)不是同一件事吗?如果是这样,请查看 Java TreeMap,看看它是否按您希望的方式工作。
Sorry for my confusion, but aren't lexicographic sorting and natural sorting (at least with Java Strings) the same thing? If so, take a look at the Java TreeMap and see if this works the way you want it to.
您无法从技术上对结构进行排序,并保证该结构将保持其顺序。 ColdFusion 有一个坏习惯,即在添加/删除节点时任意(至少据我所知)重新排序结构。
但是,您可以获取已排序键的列表,然后可以使用它来循环遍历您的结构。使用 StructSort 方法获取数组已排序的键名。您可以将排序顺序指定为
textnocase
来获取字典顺序(忽略所有大小写)。然后,您需要进行一些额外的排序,以便在此之后按值获取它们...如果您想要更多详细信息,最好发布一些您已经尝试过但不太有效的代码。
You can't technically sort a structure, and guarantee that the structure will maintain it's order. ColdFusion has a bad habit of arbitrarily (at least as far as I can tell) reordering structures when you add/remove nodes.
You can, however, get a list of sorted keys, which you can then use to loop through your struct. Use the StructSort method to get an array of sorted key names. You can specify the sort order as
textnocase
to get your lexicographic order (disregards all casing).You would then need to do some additional sorting to get them by value after that... If you want more detail, you'll be better off posting some code you've already tried that's not quite working.