Click here to Skip to main content
15,907,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I use a dictionary?

here is my code
 protected void Page_Load(object sender, EventArgs e)
        {
            string oauth_consumer_key = "fmsB2sPbs4uZv0BVxvI4w";
            string oauth_consumer_secret = "SojK6KzXJT4xtHU49SVs2iltObtUQ85e8hma9sCf4BQ";

            //Token URL
            var oauth_url = "https://api.twitter.com/oauth2/token";
            var headerFormat = "Basic {0}";
            var authHeader = string.Format(headerFormat,
                        Convert.ToBase64String(Encoding.UTF8.GetBytes(Uri.EscapeDataString(oauth_consumer_key) + ":" +
                        Uri.EscapeDataString((oauth_consumer_secret)))
                        ));

            var postBody = "grant_type=client_credentials";

            ServicePointManager.Expect100Continue = false;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(oauth_url);
            request.Headers.Add("Authorization", authHeader);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";

            using (Stream stream = request.GetRequestStream())
            {
                byte[] content = ASCIIEncoding.ASCII.GetBytes(postBody);
                stream.Write(content, 0, content.Length);
            }

            //request.Headers.Add("Accept-Encoding", "gzip");
            WebResponse response = request.GetResponse();
            Stream streamO = response.GetResponseStream();
            //byte[] responseT;
            StreamReader sreader = new StreamReader(streamO);
            string output = string.Empty;
            if(!sreader.EndOfStream)
            {
                output = sreader.ReadToEnd();
                
            }
            sreader.Close();
            streamO.Close();
            response.Close();

            WebClient wc = new WebClient();
            
            var jScript = new JavaScriptSerializer().Deserialize<dictionary><string,object>>(output);

            wc.Headers["Authorization"] = "Bearer " + Convert.ToString(jScript["access_token"]);

//            string responseS = ASCIIEncoding.UTF8.GetString(responseT);

            
            txtT.Text = wc.DownloadString("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=@wftus&count=10&trim_user=1&exclude_replies=1&contributor_details=0&include_rts=0");
            string dt = txtT.Text;

Sir here i have to use dictionary code to get text from the below file summary

}

file like - dt= [{"created_at":"Tue Aug 27 21:18:38 +0000 2013","id":372468218289340416,"id_str":"372468218289340416","text":"SAP Remote Basis Support @ $2.29\/hour\/per server. 24x7x365 Support. http:\/\/t.co\/oFuPepEB8c","source":"\u003ca href=\"http:\/\/www.tweetdeck.com\" rel=\"nofollow\"\u003eTweetDeck\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name" }]


"here i have to access data from "string dt" only text data "
output like----"SAP Remote Basis Support @ $2.29\/hour\/per server. 24x7x365 Support. http:\/\/t.co\/oFuPepEB8c"</dictionary>




thanks in advance
Posted
Updated 28-Aug-13 4:59am
v3
Comments
Maarten Kools 28-Aug-13 12:36pm    
If you don't know how a dictionary works in C#, I'd try searching Google[^] to find some tutorials on the matter.

I'm not sure I understand your question correctly, or whether you don't understand your own(?) code correctly. Because you're already using dictionaries, and you're already parsing JSON in your code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900