我试图使用 JSON 对象构造一个 JSON 字符串
我希望以这种方式构造 JSON 字符串
{
"Level": "3",
"Name": "testLogger",
"IPADDRESS": "testMachiene",
"Message": "hiiiiiiiiii",
"TimeStamp": "test12345678"
}
这是我这样做的简单程序
package com;
import org.json.JSONObject;
public class Teste {
public static void main(String args[]) throws Exception {
int loglevel = 3;
String loggerName = "testLogger";
String machieneName = "testMachiene";
String timeStamp = "test12345678";
String message = "hiiiiiiiiii";
JSONObject obj = new JSONObject();
obj.put("TimeStamp", message);
obj.put("Message", timeStamp);
obj.put("IPADDRESS", machieneName);
obj.put("Name", loggerName);
obj.put("Level", loglevel);
System.out.println(obj.toString());
}
}
它是这样建造的
{
"Name": "testLogger",
"TimeStamp": "hiiiiiiiiii",
"Message": "test12345678",
"Level": 3,
"IPADDRESS": "testMachiene"
}
我的问题是为什么它会改变属性的顺序
我可以有我想要的顺序吗??