I’m working on a word game that after each match, sends out a request to a link on this website.. It then returns a string in JSON format. This works!
However I am now left with a JSON file (that’s a string) that looks like this (example):
[
{
"word": "hello",
"phonetic": "həˈləʊ",
"phonetics": [
{
"text": "həˈləʊ",
"audio": "//ssl.gstatic.com/dictionary/static/sounds/20200429/hello--_gb_1.mp3"
},
{
"text": "hɛˈləʊ"
}
],
"origin": "early 19th century: variant of earlier hollo ; related to holla.",
"meanings": [
{
"partOfSpeech": "exclamation",
"definitions": [
{
"definition": "used as a greeting or to begin a phone conversation.",
"example": "hello there, Katie!",
"synonyms": [],
"antonyms": []
}
]
},
{
"partOfSpeech": "noun",
"definitions": [
{
"definition": "an utterance of ‘hello’; a greeting.",
"example": "she was getting polite nods and hellos from people",
"synonyms": [],
"antonyms": []
}
]
},
{
"partOfSpeech": "verb",
"definitions": [
{
"definition": "say or shout ‘hello’.",
"example": "I pressed the phone button and helloed",
"synonyms": [],
"antonyms": []
}
]
}
]
}
]
I need to know how to get specific pieces of data from this.
Here’s the code I have:
IEnumerator GetInfo(string word)
{
var request = UnityWebRequest.Get("https://api.dictionaryapi.dev/api/v2/entries/en/" + word.ToLower());
yield return request.SendWebRequest();
if(request.result != UnityWebRequest.Result.Success)
{
print("Error Fetching results");
}
else
{
string definition = request.downloadHandler.text; //Works
print(definition);
//GET DATA FROM JSON
}
}
I looked on the Unity Documentation, but really couldn’t find anything useful.
Any help would be appreciated!