0

Okay so I have a JSON that is returned from a POST function, but the problem is that the length of the JSON changes, the values are not all in set locations.

For example here is one return: http://pastebin.com/dPt4fSgN

And here is another return: http://pastebin.com/iALUPBTn

Sorry that you have to click links, I didn't know how else to put the long return on here! So what I want to access is "wins" and "losses" in "RankedSolo5x5". These can be accessed in the first return with stats[6].wins and stats[6].losses respectively. In the second return, however, the location of this data changes, causing them to be accessible with stats[11].wins and stats[11].losses. How would I account for this changing location of data to have it always return what I want, no matter where it is?

Mashiro-chan
  • 79
  • 1
  • 4
  • 8
  • Did you try iterating over the file and putting an if statement that checks whether the value of `PlayerStatSummeryType` is `RankedSolo5x5`? Once you have its index you'd be able to grab its wins and losses fields. – nevos May 03 '15 at 15:06
  • Thanks so much! I'm pretty new to programming so I don't really know a lot, even simple concepts like this ahahah.. – Mashiro-chan May 03 '15 at 17:00

1 Answers1

0

well.. I guess you should iterate the full JSON content and look for the key "RankedSolo5x5". Once you find it, you will be able to get the values.

If you don't know how to iterate a JSON file please take a look at the following link:

How do I iterate over a JSON structure?

Community
  • 1
  • 1
htobon
  • 163
  • 1
  • 7