am sorry if this was asked before but I tried looking for some answers here but I coudln't find one.
Anyway, I have similar problem with this question: Parsing JSON using Json.net
it solves some problem but am confused about my JSON data. here's the json data
{ "messages":[ { "message":"hilo", "timestamp":"23:55", "uid1":"7", "name":"shiftypowers" } ], "total_messages":"1", "last_timestamp":"1304265309", "buddylist":{ "476":{ "name":"Gandang_hari", "status":"1" }, "506":{ "name":"ichigo", "status":"1" }, "186":{ "name":"Jinn", "status":"1" }, "7":{ "name":"shiftypowers", "status":"1" }, "total":4 } }
If you noticed the numbers 476, 506, 186, and 7 - those were user id, and am going to deal with thousands of user id in the future.
The question is, how do I deserialize this?
here's my code
public class ElakoChatPollData { public ElakoChatPollData() { messages = new List(); } public List messages { get; set; } public string total_messages { get; set; } public string last_timestamp { get; set; } public buddylist buddylist { get; set; } } public class messages { public string message { get; set; } public string timestamp { get; set; } public string uid1 { get; set; } public string name { get; set; } } public class buddylist { // what should I put here ?? //public List uid { get; set; } // i don't think this is correct public Dictionary Users { get; private set; } public string total { get; set; } } public class userinfo { public string name { get; set; } public string status { get; set; } } // and serializing the json looks like this JavaScriptSerializer ser = new JavaScriptSerializer(); ChatPollData epd = ser.Deserialize<ChatPollData>(jsonchatpoll); Console.Writeline(epd.buddylist.Users[0].name); // i get Object reference not set ~~~~
if the code above is correct.. how may I able to get the user ids? and btw, the json data will be requested from drupal module (drupalchat)
"uid" : "476", "userinfo" : { "name":"Gandang_hari", "status":"1" }
– Nicky Waites