我想对这些数据进行排序,以便在JSON中显示它,这是我将自己的数据上传到实时数据库时的代码
这里有一个我想要排列的图像结果
HashMap<String, Object> map = new HashMap<>();
map.put("1_UserName", a_name);
map.put("2_phonenumber", phonenumber);
map.put("3_Date", currentDate);
map.put("4_Time", currentTime);
map.put("5_Door_acess", check_Door_acess);
map.put("6_StructuralCabling", check_StructuralCabling);
map.put("7_Lightening", check_Lightening);
map.put("8_check_FireSystem", check_FireSystem);
map.put("9_AirConditioning", check_AirConditioning);
map.put("10_Rack_01_Network", stringcheck_Rack_01_Network);
map.put("11_PowerSourceLine1R_01", PowerSourceLine1R01);
map.put("12_PowerSourceLine2_R01", PowerSourceLineR01);
map.put("13_EarthingR01", EarthingR01);
map.put("14_ofPDUsR01", ofPDUsR01editText_String11);
map.put("15_ofOutlets_PDUR01", ofOutlets_PDUR01editText_String11);
map.put("16_Horizontal_VerticalR01", Horizontal_VerticalR01);
map.put("17_PPOSWOPPR01", PPOSWOPPR01);
FirebaseDatabase.getInstance().getReference().child("ammar").setValue(map);这张来自consol的图像

发布于 2020-11-23 04:19:43
Firebase控制台完全按照预期对子键进行排序。它们按字符串值进行lexicographically排序或字典排序。它不会使用您放在每个子元素开头的数值。
如果您需要按字符串前缀对它们进行数字排序,则应该用0填充数值,以便所有数字都具有相同的宽度:
map.put("01_UserName", a_name);
map.put("02_phonenumber", phonenumber);
map.put("03_Date", currentDate);
map.put("04_Time", currentTime);
map.put("05_Door_acess", check_Door_acess);
map.put("06_StructuralCabling", check_StructuralCabling);
map.put("07_Lightening", check_Lightening);
map.put("08_check_FireSystem", check_FireSystem);
map.put("09_AirConditioning", check_AirConditioning);
map.put("10_Rack_01_Network", stringcheck_Rack_01_Network);
map.put("11_PowerSourceLine1R_01", PowerSourceLine1R01);
map.put("12_PowerSourceLine2_R01", PowerSourceLineR01);
map.put("13_EarthingR01", EarthingR01);
map.put("14_ofPDUsR01", ofPDUsR01editText_String11);
map.put("15_ofOutlets_PDUR01", ofOutlets_PDUR01editText_String11);
map.put("16_Horizontal_VerticalR01", Horizontal_VerticalR01);
map.put("17_PPOSWOPPR01", PPOSWOPPR01);如果您期望更大的数字,请使用更多的0。
https://stackoverflow.com/questions/64958989
复制相似问题