Reputation: 623
This is the json string:
{
"data": {
"translations": [
{
"translatedText": "trabajo"
}
]
}
}
I think it is the way, but it doesn't work:
[DataContract]
class Result
{
[DataMember]
public Data data { get; set; }
}
[DataContract]
class Data
{
[DataMember]
public Translations translations { get; set; }
}
[DataContract]
class Translations
{
[DataMember]
public string translatedText { get; set; }
}
Deserilazing using DataContractJsonSerializer, it gives an excepcion:
Additional information: Unable to cast object of type 'System.Collections.Generic.List1[System.Object]' to type 'System.Collections.Generic.Dictionary
2[System.String,System.Object]'.
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Result));
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
Result obj = (Result)ser.ReadObject(stream);
Upvotes: 0
Views: 401
Reputation: 8862
Rashmin is right. You can use http://json2csharp.com/ as a starting point in the future.
Upvotes: 2
Reputation: 5222
transations
is an array basically so you need to have an list of Translations
as shown below.
[DataContract]
class Data
{
[DataMember]
public List<Translations> translations { get; set; }
}
Upvotes: 1