i am doing jSon parsing in C# (ASP).The problem is that when the JSON from klout is very complex, this is the response
{"myInfluencers":[{"entity":{"id":"851563","payload":{"kloutId":"851563","nick":"YouTube","score":{"score":100.0},"scoreDeltas":{"dayChange":0.0,"weekChange":0.0,"monthChange":0.0}}}},{"entity":{"id":"100768049884337217","payload":{"kloutId":"100768049884337217","nick":"JessicaBiel","score":{"score":65.81697082519531}}}},{"entity":{"id":"879345","payload":{"kloutId":"879345","nick":"brokemogul","score":{"score":65.55970764160156},"scoreDeltas":{"dayChange":-0.2452850341796875,"weekChange":-0.6857528686523438,"monthChange":-2.5359420776367188}}}},{"entity":{"id":"25332752669424610","payload":{"kloutId":"25332752669424610","nick":"EsteeStanley","score":{"score":64.1717529296875}}}},{"entity":{"id":"28710452389286536","payload":{"kloutId":"28710452389286536","nick":"robknox_ys","score":{"score":60.353816986083984}}}}],"myInfluencees":[{"entity":{"id":"98516250154496343","payload":{"kloutId":"98516250154496343","nick":"LYNASXD","score":{"score":14.632675170898438}}}},{"entity":{"id":"42784201225370648","payload":{"kloutId":"42784201225370648","nick":"JenThackray","score":{"score":14.392120361328125}}}},{"entity":{"id":"52635827290381715","payload":{"kloutId":"52635827290381715","nick":"JTChile","score":{"score":13.279963493347168}}}},{"entity":{"id":"60235650788244656","payload":{"kloutId":"60235650788244656","nick":"upallnight356","score":{"score":11.61323070526123}}}},{"entity":{"id":"97108875505882083","payload":{"kloutId":"97108875505882083","nick":"anisahmutiahna","score":{"score":10.5490140914917}}}}],"myInfluencersCount":14,"myInfluenceesCount":25}
The classes generated are as follows
public class Score
{
public double score { get; set; }
}
public class ScoreDeltas
{
public double dayChange { get; set; }
public double weekChange { get; set; }
public double monthChange { get; set; }
}
public class Payload
{
public string kloutId { get; set; }
public string nick { get; set; }
public Score score { get; set; }
public ScoreDeltas scoreDeltas { get; set; }
}
public class Entity
{
public string id { get; set; }
public Payload payload { get; set; }
}
public class MyInfluencer
{
public Entity entity { get; set; }
}
public class Score2
{
public double score { get; set; }
}
public class Payload2
{
public string kloutId { get; set; }
public string nick { get; set; }
public Score2 score { get; set; }
}
public class Entity2
{
public string id { get; set; }
public Payload2 payload { get; set; }
}
public class MyInfluencee
{
public Entity2 entity { get; set; }
}
public class RootObject
{
public List<MyInfluencer> myInfluencers { get; set; }
public List<MyInfluencee> myInfluencees { get; set; }
public int myInfluencersCount { get; set; }
public int myInfluenceesCount { get; set; }
}
I want to bind the results with a gridview.Even if i use JSON.NET then we can’t extract the things one by one.I used deserialize before but here the scenerio is too nested.
Anyone who can help me to find a good way to solve this.Thank you in meekness
The best solution that I found was to create the small classes
Using JSON.NET
JObject o = JObject.Parse(text_klout);
influencee = o.SelectToken(“myInfluencees”).ToString();
influencer = o.SelectToken(“myInfluencers”).ToString();
Seperate them
Then iterate over each other using
JavaScriptSerializer _jsserializer = new JavaScriptSerializer();
it works…