The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Ron McLeod wrote:By design, the object's name/value pairs are unordered.
From json.org:
- An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma).
- An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).
Why does the consumer of the JSON data care if the order is preserved?
Tim Holloway wrote:And besides, you didn't even explictly order the results of your SQL query!
In SQL, there is no "natural order" to table rows, only the order imposed on a set of SELECTed data. If you don't use ORDER BY, the server is fully entitled to return the rows in a random order. Don't let past experience give you false security. In FoxPro, the order was consistently the order in which the rows had been added to the table, but in other DBMS's I've seen things like whatever order the last ordered request was told, and in the case of PostgreSQL, I saw things that made me suspect it truly did return a different random order each time.
The Java equivalent of a set of name/value pairs is a Map, and most java Map implementations don't have a natural ordering either.
Jack Tauson wrote:
Tim Holloway wrote:And besides, you didn't even explictly order the results of your SQL query!
In SQL, there is no "natural order" to table rows, only the order imposed on a set of SELECTed data. If you don't use ORDER BY, the server is fully entitled to return the rows in a random order. Don't let past experience give you false security. In FoxPro, the order was consistently the order in which the rows had been added to the table, but in other DBMS's I've seen things like whatever order the last ordered request was told, and in the case of PostgreSQL, I saw things that made me suspect it truly did return a different random order each time.
The Java equivalent of a set of name/value pairs is a Map, and most java Map implementations don't have a natural ordering either.
I see. I should probably ask the guy to put ORDER BY then.
Dave Tolls wrote:What is "SQLQUERY"?
If it's SELECT * for example then there is no order to the columns (well, it's usually the order the columns were created in).
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Dave Tolls wrote:What is "SQLQUERY"?
If it's SELECT * for example then there is no order to the columns (well, it's usually the order the columns were created in).
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Dave Tolls wrote:Out of curiosity, what JSONObject is this? .. The fact it uses put implies it's backed by a Map
Tim Holloway wrote:It's likely, but not guaranteed, that the columns would be output in collating order. However, since you're looking at a dictionary, order is immaterial - what counts is the name/value. What you actually have is an array of dictionaries, so the row order is guaranteed, but the column order is insignificant.
Speaking of which, properly, each row should contain name/value pairs, and what you are showing look more like label/value pairs. I sincerely hope that your database column names aren't really "Employee Count" and "Employee State of Residence". Aside from having spaces, the mixed upper/lower case names would be a recipe for trouble in its own right. Also, JSON is intended primarily for machine-to-machine data transport, so really a long descriptive key is mostly a waste of bandwidth.
Jack Tauson wrote:So,do you think that there is no alternative to this, if I want to have columns ordered?
Jack Tauson wrote:So,do you think that there is no alternative to this, if I want to have columns ordered?
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Consider Paul's rocket mass heater. |