如何借助数据字典从c#中的json数据访问数据 [英] how to access data from json data from c# with the help of data dictionary

查看:67
本文介绍了如何借助数据字典从c#中的json数据访问数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用字典?



这里是我的代码

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" }]





这里我必须从string dt访问数据只有文本数据



"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

推荐答案

2.29 \ / hour \ /每台服务器。 24x7x365支持。 http:\ / \ / t.co\ / oFuPepEB8c,source:\ u003ca href = \http:\ / \ / www.tweetdeck.com \ = \ nofollow\ \\\>TweetDeck\\\<\ / a\\\>, 截断:假的, in_reply_to_status_id:空, in_reply_to_status_id_str:空, in_reply_to_user_id:空, in_reply_to_user_id_str:空, in_reply_to_screen_name}]
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" }]





这里我必须从string dt访问数据只有文本数据



"here i have to access data from "string dt" only text data "

output like----"SAP Remote Basis Support @


2.29 \ / hour \ /每台服务器。 24x7x365支持。 http:\ / \ / t.co \ / oFuPepEB8c< / dictionary>
2.29\/hour\/per server. 24x7x365 Support. http:\/\/t.co\/oFuPepEB8c"</dictionary>









提前感谢





thanks in advance


这篇关于如何借助数据字典从c#中的json数据访问数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆