im having trouble translating a json response from google's apis to DataContract classes. Specifically when trying to translate an int array from JSON to an int array in the DataContract.
Heres what I have done so far.
Heres the JSON response.
{
"kind": "youtubeAnalytics#resultTable",
"columnHeaders": [
{
"name": "views",
"columnType": "METRIC",
"dataType": "INTEGER"
},
{
"name": "likes",
"columnType": "METRIC",
"dataType": "INTEGER"
},
{
"name": "dislikes",
"columnType": "METRIC",
"dataType": "INTEGER"
}
],
"rows": [
[
2162435,
871,
907
]
]
}
And heres my Data Contract classes
[DataContract]
public class AnalyticsData
{
[DataMember(Name = "kind")]
public string Kind { get; set; }
[DataMember(Name = "columnHeaders")]
public ColumnRows[] ColumnHeaders { get; set; }
[DataMember(Name = "rows")]
public int[][] rows { get; set; } //<--------
}
[DataContract]
public class ColumnRows
{
[DataMember(Name = "name")]
public string Name { get; set; }
[DataMember(Name = "columnType")]
public string ColumnType { get; set; }
[DataMember(Name = "dataType")]
public string DataType { get; set; }
}
The problem I am having is translating the 'rows' element from the JSON doc into DataContract variables, as as shown in the AnalyticsData class in the int array 'rows'.
The error I get when debugging is
System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type StudioWP8.AnalyticsData. Input string was not in a correct format. ---> System.FormatException: Input string was not in a correct format.
DataContractJsonSerializer
this works for me -- I don't get the exception. What serializer? What is the full traceback? Are these the actual classes & JSON that reproduce the bug, or are they simplifications? – dbcvar analyticsData = await request.GetValueFromRequest<AnalyticsData>(); Debug.WriteLine(analyticsData.Rows[0][1]);
– Raajit SharmaSystem.Runtime.Serialization
is a namespace not a serializer. Can you edit your question to include the full traceback of the exception? – dbc