3

次のストリームからjson値を解析しようとしています:

{"id": "tag:search.xxxxx.com,2005:xxxxxxxxxxx"}
{"body": "acordei (:"}
{"verb": "post"}
{"link": "http://xxxxx.com/rohanaf_/xxxxxxxxxx/xxxxxxxxx"}
{"generator": {
  "link": "http://xxxxx.com",
  "displayName": "web"
}}
{"postedTime": "2012-03-31T19:23:51.000Z"}
{"provider": {
  "link": "http://www.xxxxx.com",
  "displayName": "xxxxxx",
  "objectType": "service"
}}
{"object": {
  "summary": "acordei (:",
  "id": "object:search.xxxxxx.com,2005:xxxxxxxxxxxx",
  "link": "http://xxxxxxx.com/rohanaf_/statuses/xxxxxxxxxxxx",
  "postedTime": "2012-03-31T19:23:51.000Z",
  "objectType": "note"
}}
{"actor": {
  "summary": "- namorada da @srtameiga fim. ♥",
  "twitterTimeZone": "Brasilia",
  "friendsCount": 197,
  "location": {
  "displayName": "Porto Alegre ",
  "objectType": "place"
},
"link": "http://www.xxxxxxxxxx.com/rohanaf_",
"postedTime": "2010-03-31T20:12:49.000Z",
"image": "http://a0.twimg.com/profile_images/xxxxxxxxxxx/Foto1436_normal.jpg",
"links": [
   {
    "rel": "me",
    "href": null
   }
 ],
 "listedCount": 3,
 "id": "id:xxxxxxxxxxx.com:xxxxxxxxx",
 "languages": [
  "pt"
],
"utcOffset": "-10800",
"followersCount": 347,
"preferredUsername": "rohanaf_",
"displayName": ", feia  ;$",
"statusesCount": 48412,
"objectType": "person"
}}
{
 "xxxxxx_entities": {
 "urls": [],
 "hashtags": [],
 "user_mentions": []
}}
{"objectType": "activity"}
{"source": {
 "language": {
 "value": "fr"
},
 "matching_rules": [
 {
  "value": "lang:fr",
  "tag": null
}
],
}}

JSON.NETを使用して次のオプションを試しましたが、ほとんど機能しますが、いくつかのフィールドがありません(ソース:およびその子を含むすべての子)。("source")( "matching_rules")( "tag")..etc

Dim results as List(Of JToken) = jobj.Children().ToList
For each item as JProperty In results
    item.CreateReader()
    If item.name ="id" then
         id = item.value
    End If
    If item.name ="actor" then
         author = item.Value("displayName").ToString
    End If 
    If item.name="source" then
        Dim gList as IList(Of JToken)= item("matching_rules").Children.ToList
    End If 
Next

そのプロパティ名ソースのすべての子の値を取得しようとしています。JsonTextReaderを使用すると、すべてを読み取ることができますが、これは面倒でエラーが発生しやすくなります。任意の提案をいただければ幸いです。

4

1 に答える 1

6

私はそれを考え出した

If item.name = "source" then
    searchterm = item.last.selecttoken("matching_rules").first.item("value").tostring
End if
于 2012-04-09T18:04:38.783 に答える