Answer the question
In order to leave comments, you need to log in
How to make a JSON array correctly?
There is a task to compose a JSON in which an array of goods is transmitted in the form of a GUID and their quantity, they sent me a technical specification in which they want to see it like this:
{
"items": {1234: 1, 4321: 1}
}
I think that it would be correct to compose a two-dimensional an array of the form:
{
"items":
}
At least because in the future, in addition to GUID and quantity, other parameters can be passed and therefore they cannot be passed as a key:value pair . And according to the meaning of the GUID, this is exactly what the value is, and not the key. But the compilers of the TK insist. I thought, what if I'm wrong, I take it to your court.
Answer the question
In order to leave comments, you need to log in
The array in this case is much worse for the same reasons that you described. 10 parameters will be added - and dick you will understand what it means. + this does not provide uniqueness, makes it difficult to search (full enumeration if you parse directly into arrays and not into a dictionary / associative array / map).
The solution in the TK is also not nice (problems with the extension, yes), but yours is no better either.
My version, which is at least closer to the TK:
{
"items": {
1234: {
"count":1
}
}
}
{
"items": [
{
"guid":1234,
"count":1
}
]
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question