简体   繁体   中英

System.MissingMethodException: Error while deserialization of json array

I am getting error while deserializing jsonString.

Error is Type 'oodleListingsUser' is not supported for deserialization of an array.

My code of deserialization is

    string jsonString = new WebClient().DownloadString("http://api.oodle.com/api/v2/listings?key=TEST&region=region_value&category=category_value&format=json");

    JavaScriptSerializer ser = new JavaScriptSerializer();

    jsonOodleApi p = ser.Deserialize<jsonOodleApi>(jsonString);

My class defination of jsonOodleApi is

public class jsonOodleApi
{
    public oodleCurrent current;
    public oodleListings[] listings;
    public oodleMeta meta;

    public string state { get; set; }

}

Defination of oodleCurrent and oodleMeta I am not giving because its perfect !

Defination of oodleListings is

public class oodleListings
{
    public string id { get; set; }
    public string title { get; set; }

    public oodleListingsUser user;

    // I have skipped some of fields because it have no issue at all.

}

Defination of oodleListingsUser is

public class oodleListingsUser
{
    public string id { get; set; }
    public string url { get; set; }
    public string name { get; set; }
    public string photo { get; set; }
}

The problem is my jsonString sometimes returns only one value of user (type of oodleListingsUser ), and sometimes it returns array of user, and sometimes it returns null of user !

When it returns only one user, it runs perfectly fine ! No issue.

But when it returns array of user, bloom ! error occurs Type 'oodleListingsUser' is not supported for deserialization of an array.

Even I have tried public oodleListingsUser[] user But it gives error as

No parameterless constructor defined for type of 'oodleListingsUser[]'

for the value which returns only one user !

Now what should i do to solve this issue ?

Try:

public oodleListings[] listings = new oodleListings[0]; 

Or make it a List<oodleListings> perhaps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM