Diver Dan Diver Dan - 4 months ago 31
JSON Question

Deserialize a json object with an array fails with Default constructor not found for type System.String[]

I am having a little trouble trying to deserialize an object within a monotouch project using restsharp.

I have this

RestResponse<List<Product>> response = client.Execute<List<Product>> (request) as RestResponse<List<Product>>;
if (response.Data != null) {}

public class Product
{
public Product () {}
[PrimaryKey]
public string Id { get; set; }
public string Name { get; set; }

[Ignore]
public string[] ParentProductIds {
get;
set;
}


I'm getting an error of


Default constructor not found for type System.String[].


My json looks like

[
{
"Id" : "62907011-02f1-440a-92ec-dc35ecf695e0",
"Name" : "ABC",
"ParentProductIds" : ["2cedbcad-576a-4044-b9c7-08872de34a96", "3fcd12ce-8117-4ae7-ae4d-f539e4268e4d"]
},
{
"Id" : "3fcd12ce-8117-4ae7-ae4d-f539e4268e4d",
"Name" : "Name 1",
"ParentProductIds" : null
}
]


Is it due to the null ParentProductId ?

Can anyone advise what I need to do to be able to accept null arrays?

Answer

Anyone else having the same problem using a List<> instead works fine.

public List<string> ParentProductIds {
    get;
    set;