Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 反序列化为具有变量名的对象_C#_Json.net_Deserialization - Fatal编程技术网

C# 反序列化为具有变量名的对象

C# 反序列化为具有变量名的对象,c#,json.net,deserialization,C#,Json.net,Deserialization,我希望有人能帮我;我刚刚开始在一个需要进行API调用的网站上工作。我使用一个开源库进行API调用。大多数电话都很有效,但我无法让最重要的电话发挥作用。反序列化时的json字符串返回空对象 JSON字符串: {"benbeun":{"id":27266833,"name":"BenBeun","profileIconId":25,"summonerLevel":30,"revisionDate":1393655593000}} 调用,其中responseText是上面的JSON字符串:

我希望有人能帮我;我刚刚开始在一个需要进行API调用的网站上工作。我使用一个开源库进行API调用。大多数电话都很有效,但我无法让最重要的电话发挥作用。反序列化时的json字符串返回空对象

JSON字符串:

{"benbeun":{"id":27266833,"name":"BenBeun","profileIconId":25,"summonerLevel":30,"revisionDate":1393655593000}}
调用,其中responseText是上面的JSON字符串:

    public static T CreateRequest(string url)
    {
        var result = new T();
        var getRequest = (HttpWebRequest)WebRequest.Create(url);
        using (var getResponse = getRequest.GetResponse())
        using (var reader = new System.IO.StreamReader(getResponse.GetResponseStream()))
        {
            var responseText = reader.ReadToEnd();
            result = JsonConvert.DeserializeObject<T>(responseText);
        }
        return result;
    }
有什么建议吗?我已经尝试了其他问题中提供的许多选项,但我担心我的知识缺乏,无法确定我的问题所在。我觉得我与下面的代码很接近,但是它也返回一个空对象

public class SummonerDto
{

    public IDictionary<string, Summoner> Summoner { get; set; }

}

public class Summoner
{
    /// <summary>
    /// Summoner ID.
    /// </summary>
    [JsonProperty("id")]
    public long Id { get; set; }

    /// <summary>
    /// Summoner name.
    /// </summary>
    [JsonProperty("name")]
    public string Name { get; set; }

    /// <summary>
    /// ID of the summoner icon associated with the summoner.
    /// </summary>
    [JsonProperty("profileIconId")]
    public int ProfileIconId { get; set; }

    /// <summary>
    /// Date summoner was last modified specified as epoch milliseconds.
    /// </summary>
    [JsonProperty("revisionDate")]
    public long RevisionDate { get; set; }

    /// <summary>
    /// Summoner level associated with the summoner.
    /// </summary>
    [JsonProperty("summonerLevel")]
    public long SummonerLevel { get; set; }

}
公共类召唤器
{
公共IDictionary召唤器{get;set;}
}
公开课召集人
{
/// 
///召唤者ID。
/// 
[JsonProperty(“id”)]
公共长Id{get;set;}
/// 
///召唤者的名字。
/// 
[JsonProperty(“名称”)]
公共字符串名称{get;set;}
/// 
///与召唤者关联的召唤者图标的ID。
/// 
[JsonProperty(“profileIconId”)]
public int ProfileIconId{get;set;}
/// 
///上次修改召唤器的日期指定为历元毫秒。
/// 
[JsonProperty(“修订日期”)]
公共长修订日期{get;set;}
/// 
///与召唤师关联的召唤师级别。
/// 
[JsonProperty(“召集人级别”)]
公共长召唤级别{get;set;}
}
使用
字典
进行反序列化

var obj = JsonConvert.DeserializeObject<Dictionary<string,Summoner>>(json);
var obj=JsonConvert.DeserializeObject(json);

谢谢!看来我的呼吁是错误的反序列化这个对象确实。然而,我不想破坏我的代码,有没有任何方法可以让我的上述调用,为旧调用和这一个工作?
public class SummonerDto
{

    public IDictionary<string, Summoner> Summoner { get; set; }

}

public class Summoner
{
    /// <summary>
    /// Summoner ID.
    /// </summary>
    [JsonProperty("id")]
    public long Id { get; set; }

    /// <summary>
    /// Summoner name.
    /// </summary>
    [JsonProperty("name")]
    public string Name { get; set; }

    /// <summary>
    /// ID of the summoner icon associated with the summoner.
    /// </summary>
    [JsonProperty("profileIconId")]
    public int ProfileIconId { get; set; }

    /// <summary>
    /// Date summoner was last modified specified as epoch milliseconds.
    /// </summary>
    [JsonProperty("revisionDate")]
    public long RevisionDate { get; set; }

    /// <summary>
    /// Summoner level associated with the summoner.
    /// </summary>
    [JsonProperty("summonerLevel")]
    public long SummonerLevel { get; set; }

}
var obj = JsonConvert.DeserializeObject<Dictionary<string,Summoner>>(json);