Hi,
Here's a sample code and a json data
https://dev.twitter.com/rest/reference/get/followers/list
Please take a look at the json data in the above link
I have tried this
var postBody = "screen_name=" + Uri.EscapeDataString(screen_name);//
resource_url += "?" + postBody;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(resource_url);
request.Headers.Add("Authorization", authHeader);
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
var response = (HttpWebResponse)request.GetResponse();
var reader = new StreamReader(response.GetResponseStream());
var objText = reader.ReadToEnd();
myDiv.InnerHtml = objText;/*s*/
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("id_str", typeof(string));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("screen_name", typeof(string));
dt.Columns.Add("location", typeof(string));
dt.Columns.Add("description", typeof(string));
dt.Columns.Add("url", typeof(string));
dt.Columns.Add("followers_count", typeof(string));
dt.Columns.Add("friends_count", typeof(string));
dt.Columns.Add("listed_count", typeof(string));
dt.Columns.Add("created_at", typeof(string));
dt.Columns.Add("favourites_count", typeof(string));
JArray jsonDat = JArray.Parse(objText);
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonDat)))
foreach (var datas in jsonDat.users)
{
dt.Rows.Add(datas.users.id, datas.users.id_str, datas.users.name, datas.users.screen_name, datas.users.location, datas.users.description, datas.users.url, datas.users.followers_count, datas.users.friends_count, datas.users.listed_count, datas.users.created_at, datas.users.favourites_count);
}
}
Also i have created a class named users
public class users
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("id_str")]
public string id_str { get; set; }
[JsonProperty("name")]
public string name { get; set; }
[JsonProperty("screen_name")]
public string screen_name { get; set; }
[JsonProperty("location")]
public string location { get; set; }
[JsonProperty("description")]
public string description { get; set; }
[JsonProperty("url")]
public string url { get; set; }
[JsonProperty("followers_count")]
public string followers_count { get; set; }
[JsonProperty("friends_count")]
public string friends_count { get; set; }
[JsonProperty("listed_count")]
public string listed_count { get; set; }
[JsonProperty("created_at")]
public string created_at { get; set; }
[JsonProperty("favourites_count")]
public string favourites_count { get; set; }
}
}
Need help on thisThanks
17 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Salman BegPosted Oct 14, 2016, 1:58 PM
Midhun TpPosted Sep 28, 2016, 5:38 AM
Vikash KumarPosted Sep 28, 2016, 5:08 AM
Vikash KumarPosted Sep 28, 2016, 1:26 AM
Midhun TpPosted Sep 28, 2016, 1:00 AM
Vikash KumarPosted Sep 27, 2016, 10:46 AM
Error: Parse error on line 3: ... [{ "id": 16320192~"id_str": "16320192 ----------------------^ Expecting 'EOF', '}', ',', ']', got 'undefined'Now how do i go about fixing it?Midhun TpPosted Sep 27, 2016, 10:18 AM
Please validate your json data by pasting it in below link. There may be some errors with json data -
https://jsonformatter.curiousconcept.com
Vikash KumarPosted Sep 27, 2016, 10:10 AM
Unexpected JSON token when reading DataTable. Expected StartArray, got StartObject. Path '', line 1, position 1.
Midhun TpPosted Sep 27, 2016, 4:44 AM
Vikash KumarPosted Sep 27, 2016, 4:29 AM
Midhun TpPosted Sep 27, 2016, 4:21 AM
Vikash KumarPosted Sep 27, 2016, 3:53 AM
DataTable already belongs to this DataSet.
Midhun TpPosted Sep 27, 2016, 2:00 AM
Vikash KumarPosted Sep 27, 2016, 1:44 AM
Vikash KumarPosted Sep 27, 2016, 1:27 AM
Krishna Rajput SinghPosted Sep 23, 2016, 1:18 PM
Midhun TpPosted Sep 23, 2016, 9:39 AM
Please go through below links -
http://www.c-sharpcorner.com/blogs/importing-json-file-to-dataset-without-using-external-libraries
http://www.c-sharpcorner.com/blogs/convert-json-string-to-datatable-in-asp-net1