繁体   English   中英

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

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

我在反序列化jsonString时遇到错误。

错误是Type 'oodleListingsUser' is not supported for deserialization of an array.

我的反序列化代码是

    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);

我对jsonOodleApi的定义是

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

    public string state { get; set; }

}

定义oodleCurrentoodleMeta我不给予因为它的完美!

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.

}

oodleListingsUser的定义是

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

问题是我的jsonString有时只返回一个user的值( oodleListingsUser的类型),有时它返回用户的数组,有时它返回用户的null!

当它只返回一个用户时,它运行得非常好! 没有任何问题。

但是当它返回用户数组时, 绽放! 错误发生Type 'oodleListingsUser' is not supported for deserialization of an array.

即使我已经尝试过public oodleListingsUser[] user但是它给出了错误

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

对于只返回一个用户的值!

现在我该怎么做才能解决这个问题?

尝试:

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

或者将其List<oodleListings>

暂无
暂无

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

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