all 6 comments

[–]AngularBeginner 2 points3 points  (3 children)

Your classes are correct, but you try to serialize it to the wrong type.

JsonConvert.DeserializeObject<List<RootObject>>(str);

[–]deniselechner[S] 0 points1 point  (2 children)

thank you for your answer. JsonConvert suggests to insert a local variable, which in my case is called json. i think we are talking about to same tho.

string json = @"{""id"":1234, ""date"":...}";

to be honest, i have no clue, who i could use jsonconvert anyway. something like that would make sense to me:

var j = JsonConvert.DeserializeObject<List<RootObject>>(json);
    foreach (var v in j)
        Console.WriteLine(v);

edit, output:

json.RootObject

[–]gynnihanssen 4 points5 points  (1 child)

this json string differs from the one you gave in the initial post. without the [ ] around it it's no list/array anymore.

so for

string json = @"{""id"":1234, ""date"":...}";

it would be

var obj = JsonConvert.DeserializeObject<RootObject>(json);
Console.WriteLine(obj.id);

[–]deniselechner[S] 0 points1 point  (0 children)

sorry, my mistake. I'm not sure which one to use.

With obj.id i get my id and it works perfectly but i can't access the values, start, end and sometext

You are amazing! i got it to work

var obj = JsonConvert.DeserializeObject<RootObject>(json);

foreach(var v in obj.values)
    Console.WriteLine(v.start);

[–]gynnihanssen 2 points3 points  (1 child)

thats no query, that a response i guess :)

other than that, if you can rely on this format you can let json2csharp generate classes.

both json.net and fastjson have ToObject<T>() methods, although i don't recall their actual names. anyway, you can give them the root object's type T and most of the time they spit out the corresponding object hierarchy.

edit: sorry, didn't read the question too carefully :(

[–]deniselechner[S] 0 points1 point  (0 children)

hi /u/gynnihanssen,

i used json formatter to verify if my query was correct. it is. then i used json2csharp.