system.missingMethodException而:错误而JSON数组的反序列化 [英] System.MissingMethodException: Error while deserialization of json array

查看:207
本文介绍了system.missingMethodException而:错误而JSON数组的反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误反序列化jsonString。

I am getting error while deserializing jsonString.

错误是键入oodleListingsUser'不支持数组的反序列化。

反序列化我的code是

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

我班jsonOodleApi的认定中是

My class defination of jsonOodleApi is

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

    public string state { get; set; }

}

的认定中的 oodleCurrent oodleMeta 我不会放弃,因为它的完美!

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

的认定中的 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 有时仅返回一个用户值(类型的 oodleListingsUser 的),有时它返回用户的阵列,有时它会返回null用户!

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.

但是,当它返回的用户数组的绽放!的错误发生的 键入oodleListingsUser'不支持数组的反序列化。

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

连我都试过公共oodleListingsUser []用户,但它给误差

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 ?

推荐答案

尝试:

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

或者使它成为列表与LT; oodleListings方式&gt; 也许

这篇关于system.missingMethodException而:错误而JSON数组的反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆