fangyidong / json-simple

A simple Java toolkit for JSON. You can use json-simple to encode or decode JSON text.
Apache License 2.0
746 stars 338 forks source link

invalid parse string new JSONParser().parse() #120

Closed Tsyklop closed 7 years ago

Tsyklop commented 7 years ago

I have string:

{"2017-05-12":[],
"2017-05-13":[],
"2017-05-14":[],
"2017-05-15":[],
"2017-05-16":[],
"2017-05-17":[],
"2017-05-18":[],
"2017-05-19":[],
"2017-05-20":[],
"2017-05-21":[],
"2017-05-22":[],
"2017-05-23":[],
"2017-05-24":[],
"2017-05-25":[],
"2017-05-26":[],
"2017-05-27":[],
"2017-05-28":[],
"2017-05-29":[],
"2017-05-30":[],
"2017-06-01":[],
"2017-06-02":[],
"2017-06-03":[],
"2017-06-04":[],
"2017-06-05":[],
"2017-06-06":[],
"2017-06-07":[],
"2017-06-08":[],
"2017-06-09":[],
"2017-06-10":[],
"2017-06-11":[],
"2017-06-12":[],
"2017-06-13":[],
"2017-06-14":[],
"2017-06-15":[]}

As you can see, all the dates are consistent.

But after I parse the line, all the dates become chaotic. How solve this?

RalleYTN commented 7 years ago

The documentation of the JSONObject class warns you that the result is unordered.

Tsyklop commented 7 years ago

@RalleYTN And is it possible to make it orderly?

RalleYTN commented 7 years ago

Download the source code. Open the JSONObject.java Let it extend LinkedHashMap instead of HashMap. Should work but I didn't test it.

Tsyklop commented 7 years ago

@RalleYTN it works. Thanks