猿问

JSONObject:为什么JSONObject更改属性的顺序

我正在尝试使用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"

}

我的问题是为什么它会改变属性的顺序


我可以订购我想要的东西吗?


白板的微信
浏览 2370回答 3
3回答
随时随地看视频慕课网APP

相关分类

Java
我要回答