views:

604

answers:

3

A valid JSON Syntax is something of the kind:

{ "username" : "admin", "password" : "123" }

But what if I want to transmit an array of 'users' (given the example), instead of a single 'user' ?

Is the code below Valid JSON, according to the specifications?

[{ "username" : "admin", "password" : "123" }, { "username" : "bbvb", "password" : "sdfsdf" }, { "username" : "asd", "password" : "222" }]

And if not, what is the best way to transmit an array of values across with JSON? (And with 'best way', I mean syntactically)

+4  A: 

Yes, your example is valid JSON - that is exactly how you want to use an array.

Edit : Here is a good link on JSON and its usage.

Andrew Hare
A: 

The not-very-well-known page json.org has a diagram that shows the syntax. It’s extremely simple to understand, IMHO.

Bombe
A: 

What you wrote up there is already correct :)

[{ "username" : "admin", "password" : "123" }, { "username" : "bbvb", "password" : "sdfsdf" }, { "username" : "asd", "password" : "222" }]
Sikachu