In MyRequest class I have:
public static T RetrieveData<T>(Uri uri) where T : class, new()
{
return requestData<T>(query);
}
The Uri returns an array of strings such as:
{
"prop1": "JOHN",
"prop2": "JULIE",
"value": 9
},
{
"prop1": "KATE",
"prop2": "Ryan",
"value": 8
}
This is how I call my method:
var obj = MyRequest.RetrieveData<MyObject[]>("http://.....");
This is how MyObject is defined:
public class MyObject
{
public string prop1;
public string prop2;
public double value;
}
And this is the error I get:
MyObject[]' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'MyRequest.RetrieveData(uri)'
I got the method to work just fine when I tweak the uri to return just an array of 1 element and call it:
var obj = MyRequest.RetrieveData<MyObject>("http://.....");
instead of
MyObject[]
but I really need to use an array. Any thoughts?
List<MyObject>
instead? Unfortunately there's not enough information here to answer fully. – DavidG