System.MissingMethodException: Error while deserialization of json array

岁酱吖の 提交于 2019-12-20 02:27:33

问题


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 ?


回答1:


Try:

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

Or make it a List<oodleListings> perhaps.



来源:https://stackoverflow.com/questions/9173811/system-missingmethodexception-error-while-deserialization-of-json-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!