0

我从 twitter API 返回了以下 json 数据

[
   {
      "annotations":{

      },
      "resultType":"Tweet",
      "score":1.0,
      "groupName":"TweetsWithConversation",
      "results":[
         {
            "kind":"Tweet",
            "score":1.0,
            "annotations":{
               "ConversationRole":"Ancestor"
            },
            "value":{
               "created_at":"Sun Mar 03 18:54:58 +0000 2013",
               "id":308289414705082368,
               "id_str":"308289414705082368",
               "text":"Loved this Oberoi property in Gurgaon. Easily one of the best places iv ever visited!  http:\/\/t.co\/8JaCLh6fRD",
               "source":"\u003ca href=\"http:\/\/www.handmark.com\" rel=\"nofollow\"\u003eTweetCaster for iOS\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":null,
               "user":{
                  "id":53136861,
                  "id_str":"53136861",
                  "name":"Cacophonix ki Ma",
                  "screen_name":"TheSoothsayer_",
                  "location":"The city of waking dreams ",
                  "url":"http:\/\/t.co\/yquoLkXd9Y",
                  "description":"Bohemia's favourite child|Wandering minstrel at heart|Brand Manager by day |Ruffian by night| I foresee the forsaken| Tweets are personal|",
                  "protected":false,
                  "followers_count":2410,
                  "friends_count":318,
                  "listed_count":32,
                  "created_at":"Thu Jul 02 17:59:44 +0000 2009",
                  "favourites_count":89,
                  "utc_offset":19800,
                  "time_zone":"Mumbai",
                  "geo_enabled":false,
                  "verified":false,
                  "statuses_count":47897,
                  "lang":"en",
                  "contributors_enabled":false,
                  "is_translator":false,
                  "profile_background_color":"1A1B1F",
                  "profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/375039895\/twit-back.jpg",
                  "profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/375039895\/twit-back.jpg",
                  "profile_background_tile":true,
                  "profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/3356452003\/bb5078e82bb150bb09c84c8d9909e8ec_normal.jpeg",
                  "profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/3356452003\/bb5078e82bb150bb09c84c8d9909e8ec_normal.jpeg",
                  "profile_banner_url":"https:\/\/si0.twimg.com\/profile_banners\/53136861\/1360517513",
                  "profile_link_color":"2FC2EF",
                  "profile_sidebar_border_color":"FFFFFF",
                  "profile_sidebar_fill_color":"252429",
                  "profile_text_color":"666666",
                  "profile_use_background_image":true,
                  "default_profile":false,
                  "default_profile_image":false,
                  "following":null,
                  "follow_request_sent":null,
                  "notifications":null
               },
               "geo":null,
               "coordinates":null,
               "place":null,
               "contributors":null,
               "retweet_count":0,
               "favorited":false,
               "retweeted":false,
               "possibly_sensitive":false,
               "lang":"en"
            }
         },
         {
            "kind":"Tweet",
            "score":1.0,
            "annotations":{
               "ConversationRole":"Descendant"
            },
            "value":{
               "created_at":"Mon Mar 04 08:00:54 +0000 2013",
               "id":308487200348184576,
               "id_str":"308487200348184576",
               "text":"@OberoiGurgaon it was fantastic!! Thank you :)",
               "source":"\u003ca href=\"http:\/\/www.handmark.com\" rel=\"nofollow\"\u003eTweetCaster for iOS\u003c\/a\u003e",
               "truncated":false,
               "in_reply_to_status_id":308424178518867968,
               "in_reply_to_status_id_str":"308424178518867968",
               "in_reply_to_user_id":236387798,
               "in_reply_to_user_id_str":"236387798",
               "in_reply_to_screen_name":"OberoiGurgaon",
               "user":{
                  "id":53136861,
                  "id_str":"53136861",
                  "name":"Cacophonix ki Ma",
                  "screen_name":"TheSoothsayer_",
                  "location":"The city of waking dreams ",
                  "url":"http:\/\/t.co\/yquoLkXd9Y",
                  "description":"Bohemia's favourite child|Wandering minstrel at heart|Brand Manager by day |Ruffian by night| I foresee the forsaken| Tweets are personal|",
                  "protected":false,
                  "followers_count":2410,
                  "friends_count":318,
                  "listed_count":32,
                  "created_at":"Thu Jul 02 17:59:44 +0000 2009",
                  "favourites_count":89,
                  "utc_offset":19800,
                  "time_zone":"Mumbai",
                  "geo_enabled":false,
                  "verified":false,
                  "statuses_count":47897,
                  "lang":"en",
                  "contributors_enabled":false,
                  "is_translator":false,
                  "profile_background_color":"1A1B1F",
                  "profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/375039895\/twit-back.jpg",
                  "profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/375039895\/twit-back.jpg",
                  "profile_background_tile":true,
                  "profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/3356452003\/bb5078e82bb150bb09c84c8d9909e8ec_normal.jpeg",
                  "profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/3356452003\/bb5078e82bb150bb09c84c8d9909e8ec_normal.jpeg",
                  "profile_banner_url":"https:\/\/si0.twimg.com\/profile_banners\/53136861\/1360517513",
                  "profile_link_color":"2FC2EF",
                  "profile_sidebar_border_color":"FFFFFF",
                  "profile_sidebar_fill_color":"252429",
                  "profile_text_color":"666666",
                  "profile_use_background_image":true,
                  "default_profile":false,
                  "default_profile_image":false,
                  "following":null,
                  "follow_request_sent":null,
                  "notifications":null
               },
               "geo":null,
               "coordinates":null,
               "place":null,
               "contributors":null,
               "retweet_count":0,
               "favorited":false,
               "retweeted":false,
               "lang":"en"
            }
         },
         {
            "kind":"Tweet",
            "score":1.0,
            "annotations":{
               "ConversationRole":"Descendant"
            },
            "value":{
               "created_at":"Tue Mar 05 08:06:14 +0000 2013",
               "id":308850929619329024,
               "id_str":"308850929619329024",
               "text":"@OberoiGurgaon We offer excellent Annual Maintenance Contracts (AMC) to companies. In Delhi NCR Call @ 9818310092, http:\/\/t.co\/mjpC7bJ9gy",
               "source":"web",
               "truncated":false,
               "in_reply_to_status_id":308424178518867968,
               "in_reply_to_status_id_str":"308424178518867968",
               "in_reply_to_user_id":236387798,
               "in_reply_to_user_id_str":"236387798",
               "in_reply_to_screen_name":"OberoiGurgaon",
               "user":{
                  "id":201235669,
                  "id_str":"201235669",
                  "name":"dipu.true",
                  "screen_name":"diputrue",
                  "location":"India ",
                  "url":"http:\/\/t.co\/XImbmdRk",
                  "description":"Time And Tide Wait For None",
                  "protected":false,
                  "followers_count":129,
                  "friends_count":1327,
                  "listed_count":1,
                  "created_at":"Mon Oct 11 12:04:14 +0000 2010",
                  "favourites_count":0,
                  "utc_offset":19800,
                  "time_zone":"New Delhi",
                  "geo_enabled":true,
                  "verified":false,
                  "statuses_count":400,
                  "lang":"en",
                  "contributors_enabled":false,
                  "is_translator":false,
                  "profile_background_color":"C0DEED",
                  "profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png",
                  "profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png",
                  "profile_background_tile":false,
                  "profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1193522956\/A_Alphabet_normal.jpg",
                  "profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1193522956\/A_Alphabet_normal.jpg",
                  "profile_link_color":"0084B4",
                  "profile_sidebar_border_color":"C0DEED",
                  "profile_sidebar_fill_color":"DDEEF6",
                  "profile_text_color":"333333",
                  "profile_use_background_image":true,
                  "default_profile":true,
                  "default_profile_image":false,
                  "following":null,
                  "follow_request_sent":null,
                  "notifications":null
               },
               "geo":null,
               "coordinates":null,
               "place":null,
               "contributors":null,
               "retweet_count":0,
               "favorited":false,
               "retweeted":false,
               "possibly_sensitive":false,
               "lang":"en"
            }
         }
      ]
   }
]

现在我想将它反序列化为一个类型的对象TwitterResponse<TwitterRelatedTweetsCollection>。我正在使用 Newtonsoft json 库对其进行反序列化,但出现错误Cannot deserialize JSON array into type Twitterizer.TwitterResponse。我也尝试过反序列化为 type TwitterResponse<TwitterRelatedTweetsCollection>[]。它没有给出任何错误,但返回的对象为空。

使用以下代码行反序列化:-

TwitterResponse<TwitterRelatedTweetsCollection> data = JsonConvert.DeserializeObject<TwitterResponse<TwitterRelatedTweetsCollection>>(json)

将此 json 数据反序列化为 TwitterResponse 的正确方法是什么?

4

0 回答 0