c# - How to iterate over a class that contains list of two classes? - RestSharp -
this data :
{ "-jxsjfigbqqz1kqmmr0i" : { "bizcarddata" : { "company" : "tesla", "designation" : "developer", "email" : "phani@tesla.com", "name" : "phani", "phone" : "5135921241" }, "transdata" : { "date" : "15-08-29", "location" : "39.1395996,-84.5295417", "tag" : "sender", "time" : "03:17:00" } }, "-jxsjknjivtfqwe1asor" : { "bizcarddata" : { "company" : "spotify", "designation" : "designer", "email" : "komarapa@spotify.com", "name" : "phani komaravolu", "phone" : "5135921241" }, "transdata" : { "date" : "15-08-29", "location" : "39.1395996,-84.5295417", "tag" : "sender", "time" : "03:17:21" } } }
this transactions class :
public class transactions { public bizcarddata bizcarddata { get; set; } public transdata transdata { get; set; } } public class bizcarddata { public string company { get; set; } public string designation { get; set; } public string email { get; set; } public string name { get; set; } public string phone { get; set; } } public class transdata { public string date { get; set; } public string location { get; set; } public string tag { get; set; } public string time { get; set; } }
that deserialized using restsharp :
var resultlist = simplejson.deserializeobject<dictionary<string, transactions>>(content); console.writeline ("deserialized resultlist"+resultlist); foreach(var item in resultlist) { var key = item.key; var value = item.value; /* foreach(transactions go in item.value) { var bizcarddata = go.bizcarddata; var transdata = go.transdata; }*/ }
this code gives me key unique values , value transaction.
if try iterate on transaction class, getting error saying that, must implement ienumerable. how can iterated on transaction class , values.
thanks!
if don't care keys can iterate on dictionary's values (transactions).
var resultlist = simplejson.deserializeobject<dictionary<string, transactions>>(content); console.writeline ("deserialized resultlist"+resultlist); foreach(var transaction in resultlist.values) { var bizcarddata = transaction.bizcarddata; var transdata = transaction.transdata; }
if care keys, rid of second loop.
var resultlist = simplejson.deserializeobject<dictionary<string, transactions>>(content); console.writeline ("deserialized resultlist"+resultlist); foreach(var pair in resultlist) { var key = pair.key; var transaction = pair.value; var bizcarddata = transaction.bizcarddata; var transdata = transaction.transdata; }
Comments
Post a Comment