Deserializing the API - PlanetSide Universe
PSU Social Facebook Twitter Twitter YouTube Steam TwitchTV
PlanetSide Universe
PSU: Where everyone knows your name!
Home Forum Chat Wiki Social AGN PS2 Stats
Notices
Go Back   PlanetSide Universe > PlanetSide Discussions > PlanetSide 2 API Discussion

 
 
Thread Tools Search this Thread Display Modes
Old 2013-03-06, 01:03 PM   [Ignore Me] #1
Mordicant
Sergeant
 
Mordicant's Avatar
 
Deserializing the API


Anyone work with deserializing the API returns into C# classes?

Working with the Character collection I can get it to create objects for the id, name, type, currency but when I get to the stats, it shits the bed.

I am using Restsharp and checking out JSON.NET.

Any advice would be great.
Mordicant is offline  
Old 2013-03-06, 05:04 PM   [Ignore Me] #2
Goblinhunter
Private
 
Re: Deserializing the API


Yep, i'm using C# to access the API. I use JSON.net and it's really as simple as building the required class structure and then deserialising into them. I download the JSON into a string, and then run:

Code:
var root = JsonConvert.DeserializeObject<RootObject>(jsonString);
To desiarialze, starting with the root object, and it will work out the rest from there. http://json2csharp.com/ is a really useful tool to build your classes to handle the de-serialized data, just feed it your JSON and it will generate classes. They sometimes need a tweak, but it saves a lot of time.

This is a really good tutorial on Json.net - http://dotnetbyexample.blogspot.co.u...h-jsonnet.html

Also, with stats, an issue I found with the faction object under stats, is that the structure of this can vary. Some users it would return a list of strings, other (not logged on in a while) chars, it would return a list, of lists of strings, causing issues. I just had to parse out the incorrect ones.
__________________
outfitpoints.com - the Planetside 2 Outfit Management Toolkit

Last edited by Goblinhunter; 2013-03-06 at 05:09 PM.
Goblinhunter is offline  
Old 2013-03-06, 06:31 PM   [Ignore Me] #3
Mordicant
Sergeant
 
Mordicant's Avatar
 
Re: Deserializing the API


I forgot to mention that I was using JsonCsharp.com and that's what was how I got started. Thank you for the link I will check it out. Basically my end goal is to deserialize into a List<weapon> rather than having to create individual classes for each weapon as they will be adding more in the future.
Mordicant is offline  
Old 2013-03-07, 12:16 AM   [Ignore Me] #4
Mordicant
Sergeant
 
Mordicant's Avatar
 
Re: Deserializing the API


Okay, I am getting somewhere but my code is messy. But I have it going in the right direction. Thank you a bunch.
Mordicant is offline  
Old 2013-03-07, 11:35 AM   [Ignore Me] #5
maradine
Contributor
Lieutenant Colonel
 
maradine's Avatar
 
Re: Deserializing the API


I did this in GSON for the outfit node. It was ultimately overkill for what I needed to do for PS2Bot, but it's entirely possible.
maradine is offline  
 
  PlanetSide Universe > PlanetSide Discussions > PlanetSide 2 API Discussion

Bookmarks

Discord


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:16 AM.

Content © 2002-2013, PlanetSide-Universe.com, All rights reserved.
PlanetSide and the SOE logo are registered trademarks of Sony Online Entertainment Inc. © 2004 Sony Online Entertainment Inc. All rights reserved.
All other trademarks or tradenames are properties of their respective owners.
Powered by vBulletin
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.