blobfish.6712 Posted May 10, 2018 Share Posted May 10, 2018 Hello,Looking at the api documentation here: 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 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 More sharing options...
darthmaim.6017 Posted May 10, 2018 Share Posted May 10, 2018 The wiki is wrong. It's an object with the possible weapons as keys. Link to comment Share on other sites More sharing options...
Archomeda.6472 Posted May 10, 2018 Share Posted May 10, 2018 I've fixed it. Thanks for noticing! Link to comment Share on other sites More sharing options...
blobfish.6712 Posted May 10, 2018 Author Share Posted May 10, 2018 Would it not be better to just put the weapons in an array instead though, how come ArenaNet chose this approach instead? Link to comment Share on other sites More sharing options...
SlippyCheeze.5483 Posted May 11, 2018 Share Posted May 11, 2018 @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 <weapons>) { var weapon = <weapons>[key] weapon.name = key result.push(weapon)}// et viola Link to comment Share on other sites More sharing options...
blobfish.6712 Posted May 12, 2018 Author Share Posted May 12, 2018 @"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 <weapons>) { var weapon = <weapons>[key] weapon.name = key result.push(weapon)}// et violaThe 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 <string, Weapon>(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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now