【问题标题】:Cannot access child value on Newtonsoft.Json.Linq.JProperty无法访问 Newtonsoft.Json.Linq.JProperty 上的子值
【发布时间】:2012-04-18 12:01:56
【问题描述】:

我正在尝试从以下流中解析 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,我可以阅读所有内容,但这很乏味且容易出错。任何建议表示赞赏。

【问题讨论】:

    标签: vb.net twitter json.net deserialization


    【解决方案1】:

    我想通了

    If item.name = "source" then
        searchterm = item.last.selecttoken("matching_rules").first.item("value").tostring
    End if
    

    【讨论】:

      猜你喜欢
      • 2018-03-10
      • 2021-08-23
      • 2023-03-24
      • 2022-11-25
      • 1970-01-01
      • 2021-01-23
      • 2021-08-09
      • 1970-01-01
      • 2019-08-24
      相关资源
      最近更新 更多