我正在尝试解析来自twitter user_Stream api feed的json内容并尝试使用json.net和javascriptserializer,但首先需要了解json的正确格式。文件内容不断给出一个错误,即有一些无效的关闭或错过结束,我想知道是否有人知道twitter user_stream结果中一个帖子/活动的开始和结束标记是什么。在此文件中,内容从以下开始,以“转推”:false}]
结束[{"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",
"profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/125391568\/twitter_bg.gif",
"profile_background_image_url_https":
"https:\/\/si0.twimg.com\/profile_background_images\/125391568\/twitter_bg.gif",
"profile_background_tile":false,
"profile_image_url":"http:\/\/a0.twimg.com\/profile_images \/1051424405\/dbslogo_e2_4c_r_normal.gif",
"retweeted":false}]
我尝试的不同代码尝试:
Dim stringSplitter() As String = {"{"}
' split the f ile content based on the closing entry tag
sampleResults = Nothing
Try
sampleResults =
post.Split(stringSplitter, StringSplitOptions.RemoveEmptyEntries)
for each entry in sampleResults
Dim jreader2 As JsonTextReader = New JsonTextReader(New StringReader(entry))
entry = "{ " & entry & "}"
Dim js As New JavaScriptSerializer
Dim jrobj As Object = js.DeserializeObject(entry)
For Each crap As Object In CType(jrobj, Array)
Console.WriteLine(crap("id"))
Next
' Or try
Dim jobj As JObject = JObject.Parse(entry)
'Or try
dim jarr as Jarray = JArray.Parse(jarr)
Dim skipFlag As Boolean = False
Dim token As JToken = JObject.Parse(entry)
statid = token.SelectToken("id")
searchTerm = token.SelectToken("matching_rules")
Dim results As List(Of JToken) = jobj.Children().ToList
但是我得到的错误是JsonToken EndArray对于关闭jsonType对象无效