0
public class Entry
{
    public string playerOrTeamId { get; set; }
    public string playerOrTeamName { get; set; }
    public string division { get; set; }
    public int leaguePoints { get; set; }
    public int wins { get; set; }
    public int losses { get; set; }
    public bool isHotStreak { get; set; }
    public bool isVeteran { get; set; }
    public bool isFreshBlood { get; set; }
    public bool isInactive { get; set; }
}

public class SummonerId
{
    public string name { get; set; }
    public string tier { get; set; }
    public string queue { get; set; }
    public List<Entry> entries { get; set; }
}

public class RootObject
{
    public List<SummonerId> Summoner_Id { get; set; }
}

I have genereated this class using Json2csharp.com.

Where the class has 1 List I am able to access the data with no problems.

But with this class generated 2 Lists. I think I am over thinking now and have become very confused..

How can I deserialize this class

string url = json.ToString();

var root = JsonConvert.DeserializeObject<RootObject>(url):

Summoner_Id returns as null.

var id = root.Summoner_Id;

root returns as null also..

How can I solve this? Please help or point me in the right direction!

13
  • 1
    show your JSON, is it starts and ends with brackets [ and ]? Commented Apr 26, 2016 at 14:03
  • Thanks for quick reply. {"Summoner_Id":[{"name":"Fiora's Inquisitors","tier":"GOLD","queue":"RANKED_SOLO_5x5","entries":[{"playerOrTeamId":"585709","playerOrTeamName":"AP Ezreal Mid","division":"IV","leaguePoints":61,"wins":175,"losses":158,"isHotStreak":false,"isVeteran":false,"isFreshBlood":false,"isInactive":false}]}]} Commented Apr 26, 2016 at 14:04
  • This is the correctly formatted version of your JSON.... [ { "name":"Fiora's Inquisitors", "tier":"GOLD", "queue":"RANKED_SOLO_5x5", "entries":[ { "playerOrTeamId‌​":"585709", "playerOrTeamName":"AP Ezreal Mid", "division":"IV", "leaguePoints":61, "wins":175, "losses":158, "isHotStreak":fal‌​se, "isVeteran":false, "isFreshBlood":false, "isInactive":false } ] } ] Commented Apr 26, 2016 at 14:06
  • try this var root = JsonConvert.DeserializeObject<Summoner_Id>(url) and rename your SummonerId class to Summoner_Id Commented Apr 26, 2016 at 14:07
  • All the values are still returning as null. entries null, name null, queue null, tier null Commented Apr 26, 2016 at 14:09

1 Answer 1

2

This example works for me:

using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Test {
    static class Program {
        static void Main() {

            string json = @" {
    ""Summoner_Id"": [{
        ""name"": ""Fiora's Inquisitors"",
        ""tier"": ""GOLD"",
        ""queue"": ""RANKED_SOLO_5x5"",
        ""entries"": [{
            ""playerOrTeamId‌​"": ""585709"",
            ""playerOrTeamName"": ""AP Ezreal Mid"",
            ""division"": ""IV"",
            ""leaguePoints"": 61,
            ""wins"": 175,
            ""losses"": 158,
            ""isHotStreak"": false,
            ""isVeteran"": false,
            ""isFreshBlood"": false,
            ""isInactive"": false
        }]
    }]
 }";

            var root = JsonConvert.DeserializeObject<RootObject>(json);
            Console.WriteLine(root.Summoner_Id);
        }
    }

    public class Entry {
        public string playerOrTeamId { get; set; }
        public string playerOrTeamName { get; set; }
        public string division { get; set; }
        public int leaguePoints { get; set; }
        public int wins { get; set; }
        public int losses { get; set; }
        public bool isHotStreak { get; set; }
        public bool isVeteran { get; set; }
        public bool isFreshBlood { get; set; }
        public bool isInactive { get; set; }
    }

    public class SummonerId {
        public string name { get; set; }
        public string tier { get; set; }
        public string queue { get; set; }
        public List<Entry> entries { get; set; }
    }

    public class RootObject {
        public List<SummonerId> Summoner_Id { get; set; }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.