Order of JSON elements not same in Pretty and Raw view
stedero opened this issue · comments
The order in Pretty is wrong:
{
"product": {
"digest": "42d87a4e7abeb542a163f30e956b6db95c70a4b3ceb8200d46c6ca133ff9da50",
"priceUSD": 125,
"autoProcess": true,
"priceEUR": 105,
"mediaType": "Print",
"code": "030A16",
"cartEnabled": true,
"description": "Article 16 of the OECD Model Convention: History, Scope and Future",
"relatedItems": [
{
}, {
}
],
"isbn": "9789087223199",
"shippable": true,
"productType": "Book",
},
}
Raw:
{"product":{"code":"030A16","description":"Article 16 of the OECD Model Convention: History, Scope and Future","isbn":"9789087223199","priceEUR":105.0,"priceUSD":125.0,"productType":"Book","mediaType":"Print","relatedItems":["06DA16","06EA16"],"autoProcess":true,"cartEnabled":true,"shippable":true,"digest":"42d87a4e7abeb542a163f30e956b6db95c70a4b3ceb8200d46c6ca133ff9da50"}}
Can you provide a url for this response?
Can you provide a url for this response?
I'm afraid not. This service is on our company internal network. I will see if I can find a service that is exposed outside and having the same problem.
No problem, we can just put it into a github raw file to test it
Sorry for late reply.
JSON definition says:
An object is an unordered set of name/value pairs.
http://www.json.org/
The library SwiftyJSON
to analysis json, does not keep the order too.
It's hard to keep the original order, but we can sort it again by the order of alphabet.
This project relies on MGFormatter
to format json string, which relies on SwiftyJSON
to read and analysis json.
To keep the same order, all of MGFormatter
have to be rewritten.
I will try to find a library which can analysis json as the same order as the original string.
If you find any library, please told me.
Anyway, rewriting it by myself is impossible, cost a lot of time and cause unknown errors.
I will sort json keys by the order of alphabet, and update this project, hope you like it.