如何维护JSONObject的顺序 [英] How to maintain the order of a JSONObject
本文介绍了如何维护JSONObject的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 JSONObject 来删除certin属性我不需要JSON字符串:
I am using a JSONObject in order to remove a certin attribute I don't need in a JSON String:
JSONObject jsonObject = new JSONObject(jsonString);
jsonObject.remove("owner");
jsonString = jsonObject.toString();
它运行正常但问题是JSONObject是无序的名称/值对集合我希望在它经历JSONObject操作之前保持String的原始顺序。
It works ok however the problem is that the JSONObject is "an unordered collection of name/value pairs" and I want to maintain the original order the String had before it went through the JSONObject manipulation.
知道如何做到这一点吗?
Any idea how to do this?
推荐答案
你不能。
这就是为什么我们称之为无序的名称/值对集合。
That is why we call it an unordered collection of name/value pairs.
为什么你需要这样做,我不确定。但是如果你想要订购,你将不得不使用一个json数组。
Why you would need to do this, I'm not sure. But if you want ordering, you'll have to use a json array.
这篇关于如何维护JSONObject的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文