简体   繁体   English

System.MissingMethodException:反序列化json数组时出错

[英]System.MissingMethodException: Error while deserialization of json array

I am getting error while deserializing jsonString. 我在反序列化jsonString时遇到错误。

Error is Type 'oodleListingsUser' is not supported for deserialization of an array. 错误是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 我对jsonOodleApi的定义是

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 ! 定义oodleCurrentoodleMeta我不给予因为它的完美!

Defination of oodleListings is oodleListings的定义是

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 oodleListingsUser的定义是

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 ! 问题是我的jsonString有时只返回一个user的值( oodleListingsUser的类型),有时它返回用户的数组,有时它返回用户的null!

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. 错误发生Type 'oodleListingsUser' is not supported for deserialization of an array.

Even I have tried public oodleListingsUser[] user But it gives error as 即使我已经尝试过public oodleListingsUser[] user但是它给出了错误

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. 或者将其List<oodleListings>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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