0

I would like to turn this into a class so I can parse it... but http://json2csharp.com/ gives it an error.. i think i would be able to do it myself but the variables like "red team" and "ban name" all have spaces in its name.. so that completely throws me off........

and also the fact that there's a "red team" and a "blue team" kinda throws me off as the examples i see on the internet don't have two different classes in a file.. getting frustrated can anyone help? trying to learn JSON.net but having trouble parsing everything

{
    "red team": {
        "ban name": [
            "Corkii", 
            "Darius", 
            "Diana"
        ], 
        "ban number": [
            14, 
            15, 
            16
        ], 
        "players": [
            "Nien", 
            "bigfatlp", 
            "Link", 
            "Doublelift", 
            "Chauster"
        ], 
        "pick rate": [
            0.7, 
            0.5, 
            0.8, 
            0.9, 
            0.6
        ], 
        "pick number": [
            6, 
            7, 
            8, 
            9, 
            10
        ], 
        "team": "Counter Logic Gaming", 
        "pick name": [
            "Anivia", 
            "Annie", 
            "Ashe", 
            "Blitzcrank", 
            "Brand"
        ], 
        "pick win rate": [
            0.6, 
            0.7, 
            0.8, 
            0.9, 
            0.5
        ]
    }, 
    "blue team": {
        "ban name": [
            "Caitlyn", 
            "Cassiopeia", 
            "Chogath"
        ], 
        "ban number": [
            11, 
            12, 
            13
        ], 
        "players": [
            "Dyrus", 
            "TheOddOne", 
            "Reginald", 
            "WildTurtle", 
            "Xpecial"
        ], 
        "pick rate": [
            0.2, 
            0.5, 
            0.3, 
            0.4, 
            0.1
        ], 
        "pick number": [
            1, 
            2, 
            3, 
            4, 
            5
        ], 
        "team": "TSM Snapdragon", 
        "pick name": [
            "Aatrox", 
            "Ahri", 
            "Akali", 
            "Alistar", 
            "Amumu"
        ], 
        "pick win rate": [
            0.1, 
            0.2, 
            0.3, 
            0.4, 
            0.5
        ]
    }
user1189352
  • 3,628
  • 12
  • 50
  • 90
  • Have you tried by removing spaces? – PratikP24 Dec 12 '13 at 06:03
  • i can't remove the spaces in the file though.. so if i wanted to say make a class for ban name.. i can't just do "string ban name".. that'll error in visual studio.. and from what i'm reading..to deserialize correctly the class variables have to match what's in the json file? – user1189352 Dec 12 '13 at 06:05

1 Answers1

1

Checking your JSON with JSONLint, I get:

Parse error on line 1:
"redteam": {    "ba
^
Expecting '{', '['

You have to start your JSON with a {, and end it with a corresponding }. If you add those characters, and allow JSONLint to remove the excess spaces, you get this:

public class Redteam
{
    public List<string> banname { get; set; }
    public List<int> bannumber { get; set; }
    public List<string> players { get; set; }
    public List<double> pickrate { get; set; }
    public List<int> picknumber { get; set; }
    public string team { get; set; }
    public List<string> pickname { get; set; }
    public List<double> pickwinrate { get; set; }
}

public class Blueteam
{
    public List<string> banname { get; set; }
    public List<int> bannumber { get; set; }
    public List<string> players { get; set; }
    public List<double> pickrate { get; set; }
    public List<int> picknumber { get; set; }
    public string team { get; set; }
    public List<string> pickname { get; set; }
    public List<double> pickwinrate { get; set; }
}

public class RootObject
{
    public Redteam redteam { get; set; }
    public Blueteam blueteam { get; set; }
}
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
  • that can't be right.. i got the same when i put it into that website... but everything says "___invalid_name__".. that's why i came here – user1189352 Dec 12 '13 at 06:06
  • will the deserialization with json.net work like this? from what i'm reading it won't? – user1189352 Dec 12 '13 at 06:06
  • JSONLint removes the excess spaces from the names. The names are invalid with the spaces. It's not gonna work with invalid JSON. – Robert Harvey Dec 12 '13 at 06:09
  • 1
    How are you able to use it if it's invalid JSON? You could try this: http://stackoverflow.com/questions/6860602/json-net-jsonserializer-attribute-for-custom-naming – Robert Harvey Dec 12 '13 at 06:22
  • hm that last link may work.. i hope. will get back to you after i try – user1189352 Dec 12 '13 at 06:25