我想從使用JObject
解析C#中的Twitter的JSON對象我似乎無法弄清楚起點在哪裏,我需要的結果。例如:解析來自鳴叫的JSON
我需要得到以下幾點:
- 頭像URL
- Twitter的名字
- 消息
JSON字符串如下所示:
{「completed_in」:0.01,「max_id」:297026363595042816,「max_ id_str「:」297026363595042816「,」page「:1,」query「:」UOL01「,」refresh_url「:」?since_id = 297026363595042816 & q = O1「,」results「:[{」created_at「:」Thu,31 Jan 2013 16:59:38 +0000「,」from_user「:」CarrieLouiseH「,」from_user_id「:252240491,」from_user_id_str「:」252240491「,」from_user_name「:」Carrie Haworth「,」geo「:null,」id 「:297026363595042816」 ID_STR 「:」 297026363595042816" , 「iso_language_code」: 「NL」, 「元數據」:{ 「result_type的」: 「最近」}, 「profile_image_url」:「http://a0.twimg.com/profile_images /1721499350/5680_216695890261_521090261_7945528_588811_n_normal.jpg","profile_image_url_https":"https://si0.twimg.com/profile_images/1721499350/5680_216695890261_521090261_7945528_588811_n_normal.jpg","source 「:」 < A HREF = " http://twitter.com/ " > web </a >「,」text「:」Test#01「,」to_user「:null,」to_user_id「:0,」to_user_id_str「:」0「,」to_user_name「:null}] 「results_per_page」:15, 「since_id」:0, 「since_id_str」: 「0」}
我的假設是,如果我開始在 「結果」 然後我可以有機會獲得 「FROM_USER」 等。這裏是我的代碼(到目前爲止):
void DownloadStringCompleted(object senders, DownloadStringCompletedEventArgs e)
{
try
{
List<TwitterItem> contentList = new List<TwitterItem>();
JObject ja = JObject.Parse(e.Result);
int count = 0;
JToken jUser = ja["results"];
var name2 = (string)jUser["from_user_name"];
}catch(Exception e){
MessageBox.Show("There was an error");
}
}
但是,這似乎只是捕捉異常。任何人有任何想法,我去哪裏錯了?
檢查異常以獲取更多信息,尤其是e.Message ... – CodeZombie