I’m working on my own small Twitter application in C#.
I’ve managed to serialize the json data from https://api.twitter.com/1/followers/ids.json?cursor=-1&screen_name=
It returns something like this:
{ "ids" : [ 401295021,
506271294,
14405250,
25873220
],
"next_cursor" : 0,
"next_cursor_str" : "0",
"previous_cursor" : 0,
"previous_cursor_str" : "0"
}
Using this class I can serialize it:
[DataContract]
public class TwitterFollowers
{
[DataMember(Name = "ids")]
public IList<int> AccountIDs { get; set; }
}
Now I want to get the screen names of the followers so I use this url:
http://api.twitter.com/1/users/lookup.json?user_id=
This json looks like this:
[ { "contributors_enabled" : false,
"created_at" : "Wed Apr 16 06:30:52 +0000 2008",
"default_profile" : false,
"default_profile_image" : false,
"description" : "",
"utc_offset" : -25200,
"verified" : false
},
{ "contributors_enabled" : false,
"created_at" : "Tue Mar 04 12:31:57 +0000 2008",
"default_profile" : true,
"default_profile_image" : false,
"description" : "",
"utc_offset" : 3600,
"verified" : false
}
]
As you can see the array starts right away, without naming it.
How should my class look like to serialize this?
I’ve tried this, but that doesn’t work:
[DataContract]
public class TwitterProfiles
{
[DataMember(Name = "")]
public IList<TwitterProfile> Profiles { get; set; }
}
[DataContract]
public class TwitterProfile
{
[DataMember(Name = "lang")]
public string Language { get; set; }
[DataMember(Name = "location")]
public string Location { get; set; }
[DataMember(Name = "name")]
public string Name { get; set; }
[DataMember(Name = "screen_name")]
public string ScreenName { get; set; }
[DataMember(Name = "url")]
public string URL { get; set; }
}
Have you tried removing the “Name” property off of the DataMember attribute all together? Meaning:
If that doesn’t work, one option you could also do is grab the output from the api call, and format it into a json string that you know you can deserialize: