【问题标题】:twitter json - unable to convert to jobject or jarray using json.net / javascriptserializertwitter json - 无法使用 json.net / javascriptserializer 转换为 jobject 或 jarray
【发布时间】:2012-05-09 14:11:49
【问题描述】:

我已经被困在这个问题上 3 天了...我一直在访问 twitter api 来获取用户列表的 user_timeline 并且返回的 json 无法使用。我尝试使用 javascriptserializer 反序列化它并得到一个错误:

传入的对象无效,':'或'}'

现在这令人沮丧,因为我希望返回的 json 没有错误。然后我尝试了 json.net 并使用 string.split 拆分帖子并尝试将每个帖子转换为 Jobject 或 jarray。对于 Jarray 我得到了

'加载 jArray 时内容意外结束

对于作业:

'从 jsonreader 读取 JObject 时出错。当前 jsonreader 项不是对象,StartArray'

这真是令人沮丧。

这里是 json 开头和结尾的示例:

[{"created_at":"Tue May 08 10:30:05 +0000   2012","id":199808381991653377,
  "id_str":"199808381991653377",
  "text":"@waddehawk Sorry for the misinformation earlier,
          this should be tomorrow after 2pm.",
  "source":"\u003cahref=\"http:\/\/www.awarenessnetworks.com\/home\/\"                              
  "truncated":false,
  "in_reply_to_status_id":199796940358156288,
  "in_reply_to_status_id_str":"199796940358156288",
  "in_reply_to_user_id":333905755,"in_reply_to_user_id_str":"333905755",
  "in_reply_to_screen_name":"waddehawk",
  "user":
  {"id":95310018,"id_str":"95310018",
  "name":"DBS Bank","screen_name":"dbsbank","location":"Singapore",
  "description":"The DBS official channel, 
  we're here Mon-Fri, 9am-6pm. Otherwise, call us 
  at 18001111111 or contact us via www.dbs.com\/contact",
  "url":"http:\/\/www.dbs.com","protected":false,
  "followers_count":1350,"friends_count":173,"listed_count":58,
  "created_at":"Tue Dec 08 00:07:04 +0000           2009","favourites_count":0,"utc_offset":28800,
  "time_zone":"Singapore","geo_enabled":false,
  "verified":false,"statuses_count":306,"lang":"en",
  "contributors_enabled":false,"is_translator":false,
  "profile_background_color":"CC0000",
  "coordinates":null,"place":null,"contributors":null,
  "retweet_count":1,"favorited":false,"retweeted":false,"possibly_sensitive":false}]
  {"created_at":"Tue May 08 19:45:51 +0000   2012","id":199948247710703616,
  "id_str":"199948247710703616",
 "text":"@mhess4 We agree! We still have several days to go. Hope you'll 
    be able to  make it to one of our stops before Fri!",
  "source":"\u003ca href=\"http:\/\/www.exacttarget.com
  \/products\/social.aspx?utm_source=sp1\" rel=\"nofollow\"\u003eSocialEngage\u003c\/a\u003e",
 "truncated":false,"in_reply_to_status_id":199527746962071553,
 "in_reply_to_status_id_str":"199527746962071553",
 "in_reply_to_user_id":36889749,"in_reply_to_user_id_str":"36889749",
 "in_reply_to_screen_name":"mhess4","user":
 {"id":80374332,"id_str":"80374332","name":"Citibank",
  "screen_name":"Citibank","location":"","description":"Special offers, 
  ideas for managing your financial life, and 
   other updates from  Citibank","url":"http:\/\/www.citi.com",
  "protected":false,
  "followers_count":9221,"friends_count":8454,
  "listed_count":245,"created_at":"Tue Oct 06 18:49:45 +0000 2009","favourites_count":0,"utc_offset":-18000,
 "time_zone":"Quito","geo_enabled":false,"verified":true,
 "statuses_count":1592,"lang":"en","contributors_enabled":true,
 "is_translator":false,"profile_background_color":"C0DEED",
 "profile_background_image_url":"http:\/\/a0.twimg.com
 \/profile_background_images\/95956292\/twitter_bg_1280x1024.jpg",
 "profile_background_image_url_https":"https:\/\/si0.twimg.com
 \/profile_background_images\/95956292\/twitter_bg_1280x1024.jpg",
 "profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com
  \/profile_images\/853331211\/citi-co-r-3d_sm_rgb_normal.jpg","profile_image_url_https":
"https:\/\/si0.twimg.com\/profile_images\/853331211\/citi-co-r-3d_sm_rgb_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,
 "show_all_inline_media":false,"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},..

现在我已经在此处格式化了代码并且没有粘贴整个文件,但它对我来说确实是有效的 json,并且在从 twitter api 接收到流后我没有更改任何内容。有人可以指出我正确的方向吗?我真的需要解析这些东西吗?

【问题讨论】:

    标签: vb.net json json.net javascriptserializer


    【解决方案1】:

    无论如何,想通了。太恐慌了,没有看到明显的解决方案。我只是确保我清理了 json 并使用在线 http://jsonformatter.curiousconcept.com/ 对其进行了验证 清洁器。这样做并能够使用 json.net 转换为 JObject

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多