Because I want to use the conversion CSV file function in org.json, I must use org.json. and the csv order is the same as JSONArray, so I need a correct Order JSONArray. I found that JSONArray order is the same as put into it, but JSONObject is order by 'a-z', How to make the order of jsonObject the same as when I put it. my code is :
org.json.JSONObject jsonObject = new org.json.JSONObject();
jsonObject.put("text1","111");
jsonObject.put("abc1","111");
org.json.JSONObject jsonObject2 = new org.json.JSONObject();
jsonObject2.put("text2","222");
jsonObject2.put("abc2","222");
JSONArray jsonArray = new JSONArray();
jsonArray.put(jsonObject);
jsonArray.put(jsonObject2);
System.out.println(jsonObject);
System.out.println(jsonObject2);
System.out.println(jsonArray);
The result is
{"abc1":"111","text1":"111"}
{"text2":"222","abc2":"222"}
[{"abc1":"111","text1":"111"},{"text2":"222","abc2":"222"}]
but I want
{"text1":"111","abc1":"111"}
{"text2":"222","abc2":"222"}
[{"text1":"111","abc1":"111"},{"text2":"222","abc2":"222"}]