Reading from a JSON file

Updated on January 9, 2017 in [A] Other Answers
Share on Facebook0Tweet about this on Twitter0Share on Google+0Share on Reddit0
8 on January 7, 2017

I am learning C# and Unity. I am working on a simple hangman game for android. To get a random word I generate a random number which is used for finding a word from a word list text file (using stream readers and resource folder). Now I want to implement so that I have a json file, so for every category of word I have easy, medium and hard, and for every difficulty there are words. I haven’t made the json file yet since I don’t know if it is possible to read the json file in some way. I searched for unity json and got json serialization which didn’t help me much since I didn’t understand it.

  • Liked by
Reply
6 on January 7, 2017

Did you find this?
https://docs.unity3d.com/Manual/JSONSerialization.html 
 
If you read it very carfully, I think you can follow it.

on January 7, 2017

I did understand it a bit, but how would I make it so under category I got words (nested). In the unity docs it shows how can one object have several properties and transform it into json.

Guru
on January 7, 2017

Hmmm yeah, I see.
JSON works with objects…
Maybe it’s better for you to look into XML.

Wise
on January 7, 2017

Binary Formaters ftw

Guru
on January 7, 2017

Yes, but the goal is that he can write the file himself. So, binary formatters won’t work with that.

on January 7, 2017

Or is there another way of implementing the concept of categories and difficulty for each word?

on January 7, 2017

I will try the xml route, but don’t have time today so it will have to wait.

Show more replies
  • Liked by
Reply
Cancel
0 on January 9, 2017

I’m not sure if I understand exactly what you’re trying to implement.

Are you trying to have categories and within that have words that are assigned with a number(id)? you could probably set up structs to store each word and additional info, which would be less resource intensive

Then would it be okay to have an array that would represent multiple data?

I was trying to something similar and I came across this that helped me a lot

http://stackoverflow.com/questions/36239705/deserialization-of-json-using-minijson-in-unity-c-sharp/36244111#36244111

  • Liked by
Reply
Cancel