Parse Json Array of Strings to Object C#
I'm working with a legacy system that is using a Generic Method to Deserialize Json Responses to Objects using Newtonsoft.Json as Follows:
responseData = JsonConvert.DeserializeObject<TResponse>(responseData);
I'm trying to deserialize this response:
[
"LA1_1200099253",
"LA1_1200030493",
"LA1_1200005581",
"LA1_1199533163",
"LA1_1199521680",
"LA1_1199500161",
"LA1_1199445213",
"LA1_1199385918",
"LA1_1198691674",
"LA1_1198584599",
"LA1_1198580864",
"LA1_1198199891",
"LA1_1198193839",
"LA1_1197677005",
"LA1_1197387180",
"LA1_1197178604",
"LA1_1197195621",
"LA1_1197149865",
"LA1_1197164149",
"LA1_1197050213"
]
But I'm getting this exception:
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: [. Path '', line 1, position 1.
When trying to map the response to this class:
public class MatchesResponse : ResponseBase
{
public List<string> Games { get; set; } = new List<string>();
}
Does anyone know what I could do?. Thanks in Advance
Solution 1:
try this
var response = new MatchesResponse
{
Games = JsonConvert.DeserializeObject<string[]>(responseData);
}