c# - Questioning received JSON structure -


i'm using beta api (http://developer.riotgames.com/api/methods) returns json exposed methods. i've been able use json.net deserialize of these return values far. however, today consumed 1 of function returns json valid in opinion not correct.

you're wondering, why don't ask on beta forum? have haven't received answer far , in general intrigues me.

a snippet of json return:

    "1001": {      "name": "boots of speed",      "plaintext": "slightly increases movement speed",      "group": "bootsnormal",      "description": "<...     } 

the problem have structure id used "group" without identifier. able use decently if had

"itemid" : "1001" 

but doesn't have that. don't mind manually parsing i'd first know whether or not json correct (not valid).

do agree not clean way of creating json block contains list of elements or missing here? far haven't seen comments on beta forum of api i'm wondering why.

edit "valid" vs "correct/usable": know it's valid json statement. i'm questioning fact whether usable json.net.

i have following class definition (with 2 subclasses):

public class jsonitem {     [jsonproperty("tags")]     public string[] tags { get; set; }      [jsonproperty("plaintext")]     public string plaintext { get; set; }      [jsonproperty("description")]     public string description { get; set; }      [jsonproperty("name")]     public string name { get; set; }      [jsonproperty("into")]     public string[] { get; set; }      [jsonproperty("image")]     public jsonitemimage image { get; set; }      [jsonproperty("colloq")]     public string colloq { get; set; }      [jsonproperty("gold")]     public jsonitemgold gold { get; set; } } 

when giving above json block to jsonconvert.deserializeobject(json) throws error because "1001" not mentioned in jsonitem. how handle can use json.net?

a class won't work because have no names give properties:

public class jsonitemwrapper {     [jsonproperty("")]     public string id { get; set; }     [jsonproperty("")]     public jsonitem myproperty { get; set; } } 

edit: "consistent other methods" other methods return blocks every property within {} , has identifier. added function have "primary key outside of {}" style.

it valid json , can use type dictionary<string, someobject> deserialize json.

string json = @"{     ""1001"": {             ""name"": ""boots of speed"",             ""plaintext"": ""slightly increases movement speed"",             ""group"": ""bootsnormal"",             ""description"": ""desc...""         }     }";   var dict = jsonconvert.deserializeobject<dictionary<string, myobject>>(json);  

and accesing item later on key can fast too.


public class myobject {     public string name { get; set; }     public string plaintext { get; set; }     public string group { get; set; }     public string description { get; set; } } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -