亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 .json 文件獲取特定值

如何從 .json 文件獲取特定值

C#
收到一只叮咚 2023-09-16 17:44:26
我有一個 JSON 文件,我需要捕獲特定的鍵值才能在我的 JSON 代碼中執行此操作{    "uri": "https://wmg.nfa.futures.org/news/EnforceRegActions5imple.aspx",      "children": [    {        "uri": "https://www.nfa.futures.ortnews/EnforceRegActions5imple.aspx#145View%209%28e1233a13%401",        "children": [            {                "uri": "httpsghomm nfa futures org/news/EnforceReeActions5imple aspx#114Rule4%28e6ea03f2%400%40145View%209%28e1233a13%401",                "title": "Compliance Rules : Rule 2-2 : Rule",                "type": "Enforcement and Registration Actions : Rule",                "publishedDate": "2019-08-15",                "cachedDateTimeOffset": "0001-01-01700:00:00+00:00",            },            {                "uri": "httos./Pv'm nfa futures ore/news/EnforceReioctions5imple           aspx#114Rule4%28e6ea03f2%401%40145view%209%28e1233a13%401",                "title": "Compliance Rules : Rule 2-4 : Rule",                "type": "Enforcement and Registration Actions : Rule",                "publishedDate": "2019-08-15",                "cachedDateTimeOffset": "0001-01-01T00:00:00+00:00",            }        ]當我調試時,我可以看到所有值,但無法選擇特定的值,我也嘗試過 SElECTED Token 但沒有運氣。我的問題是這有兩個孩子 json 一個有 HTML 鍵另一個沒有我需要獲取第一個孩子我需要第二個孩子我需要的 HTML 值但是當我嵌套循環時它總是選擇第一個節點如何解決這個問題
查看完整描述

3 回答

?
慕后森

TA貢獻1802條經驗 獲得超5個贊

下面的內容應該可以解決問題。


JArray data = (JArray)parsed["children"];


foreach(JObject children in (JObject)data){

  foreach(JObject child in (JArray)children["children"]){

     var value = child["html"];

  }


}


查看完整回答
反對 回復 2023-09-16
?
紅糖糍粑

TA貢獻1815條經驗 獲得超6個贊

也許這個例子會有所幫助:


string json = @"{

  'channel': {

    'title': 'James Newton-King',

    'link': 'http://james.newtonking.com',

    'description': 'James Newton-King\'s blog.',

    'item': [

      {

        'title': 'Json.NET 1.3 + New license + Now on CodePlex',

        'description': 'Announcing the release of Json.NET 1.3, the MIT license and the source on CodePlex',

        'link': 'http://james.newtonking.com/projects/json-net.aspx',

        'categories': [

          'Json.NET',

          'CodePlex'

        ]

      },

      {

        'title': 'LINQ to JSON beta',

        'description': 'Announcing LINQ to JSON',

        'link': 'http://james.newtonking.com/projects/json-net.aspx',

        'categories': [

          'Json.NET',

          'LINQ'

        ]

      }

    ]

  }

}";


JObject rss = JObject.Parse(json);


string rssTitle = (string)rss["channel"]["title"];


string itemTitle = (string)rss["channel"]["item"][0]["title"];


JArray categories = (JArray)rss["channel"]["item"][0]["categories"];


查看完整回答
反對 回復 2023-09-16
?
森欄

TA貢獻1810條經驗 獲得超5個贊

我看不到圖片,但你可以通過:

parsed["key"];


查看完整回答
反對 回復 2023-09-16
  • 3 回答
  • 0 關注
  • 174 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號