Jump to content
  • Sign Up

Professions -> Weapons not an array?


blobfish.6712

Recommended Posts

Hello,

 

Looking at the api documentation here: [https://wiki.guildwars2.com/wiki/API:2/professions](https://wiki.guildwars2.com/wiki/API:2/professions "https://wiki.guildwars2.com/wiki/API:2/professions") it says that "weapons" is supposed to be an array ("weapons (array of objects)"). If i look at an actual request, for example: [https://api.guildwars2.com/v2/professions/Engineer](https://api.guildwars2.com/v2/professions/Engineer "https://api.guildwars2.com/v2/professions/Engineer") the weapon array is sent like this: "weapons": {...} when it should be "weapons":[{...}, {...}, ...] or am I misunderstanding something?

Link to comment
Share on other sites

> @"blobfish.6712" said:

> Would it not be better to just put the weapons in an array instead though, how come ArenaNet chose this approach instead?

 

Probably not. Enumerating the direct properties of a JSON Object is trivial, and it binds the name and value in a way that is popular. (I mean, personally, I strongly prefer fully internal data, so I agree with you, but ... this is a popular choice, and it does work.)

 

If you prefer an array of objects, simply use some variant of the code:

 

var result = new Array()

for (var key in ) {

var weapon = [key]

weapon.name = key

result.push(weapon)

}

// et viola

Link to comment
Share on other sites

> @"SlippyCheeze.5483" said:

> Probably not. Enumerating the direct properties of a JSON Object is trivial, and it binds the name and value in a way that is popular. (I mean, personally, I strongly prefer fully internal data, so I agree with you, but ... this is a popular choice, and it does work.)

>

> If you prefer an array of objects, simply use some variant of the code:

>

> var result = new Array()

> for (var key in ) {

> var weapon = [key]

> weapon.name = key

> result.push(weapon)

> }

> // et viola

 

The problem this approach brings to me is that the library i use (newtonsoft.json) can't de-serialize the weapons into a dictionary of type (at least i couldn't get it to). This means i have to make a big ugly class containing one JsonProperty per weapon and then i have to check which ones has been initialized. This will also be a problem for me when they add new weapons and i then have to add those to the "Weapons" class.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...