Question by
gunboldb · Jan 24, 2019 at 06:15 AM ·
wwwjsonapiserializabledeserialize
Deserialize JSON with a certain structure using JsonUtility
I am trying to deserialize a JSON with the following format:
{
"id": "id_1",
"data": [{
"words": "unity answers",
"score": 50.0,
"single_word": [{
"word": "unity",
"description": "game engine",
"rating": 42.0
},
{
"word": "answers",
"description": "questions",
"rating": 69.0
}]
}],
"language": "english",
"request_id": "id_1-64_18420118121894",
"time": "2019-01-24T05:12:49.121Z"
}
Also:
[Serializable]
public class JsonResponse
{
public string id;
public string? data;
public string langauge;
public string request_id;
public string time;
}
I need to access what's inside "data" (same with "single_word"). I guess its not really a string, and I have tried with list (list of strings, then have another class for it and deserialize again, like a nested json), dictionary and arrays but I am getting nothing.
Can anyone help me figure this out?
Comment
Best Answer
Answer by gunboldb · Jan 25, 2019 at 10:58 PM
Got it. In case anyone needs it:
[Serializable]
public class JSON
{
public string id;
public Data[] data;
public string language;
public string result_id;
public string time;
[Serializable]
public class Data
{
public string words;
public string score;
public Single_word[] single_word;
[Serializable]
public class Single_word
{
public string word;
public string description;
public string rating;
}
}
}