最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#使用Newtonsoft.Json中的JObject對象

 更新時間:2022年07月23日 09:34:57   作者:熊思宇  
本文詳細講解了C#使用Newtonsoft.Json中JObject對象的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

案例1

json

{
?? ?"Name": "Jack",
?? ?"Age": 34,
?? ?"Colleagues": [{
?? ??? ?"Name": "Tom",
?? ??? ?"Age": 44
?? ?}, {
?? ??? ?"Name": "Abel",
?? ??? ?"Age": 29
?? ?}]
}

代碼

using Newtonsoft.Json.Linq;
using System;
?
namespace JObject案例
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? string json = "{\"Name\" : \"Jack\", \"Age\" : 34, \"Colleagues\" : [{\"Name\" : \"Tom\" , \"Age\":44},{\"Name\" : \"Abel\",\"Age\":29}] }";
? ? ? ? ? ? JObject jObject1 = JObject.Parse(json);
?
? ? ? ? ? ? string name = jObject1["Name"].ToString();
? ? ? ? ? ? string age = jObject1["Age"].ToString();
?
? ? ? ? ? ? string colleagues1_name = jObject1["Colleagues"][0]["Name"].ToString();
? ? ? ? ? ? string colleagues1_age = jObject1["Colleagues"][0]["Age"].ToString();
?
? ? ? ? ? ? Console.WriteLine(name);
? ? ? ? ? ? Console.WriteLine(age);
? ? ? ? ? ? Console.WriteLine(colleagues1_name);
? ? ? ? ? ? Console.WriteLine(colleagues1_age);
?
? ? ? ? ? ? Console.ReadKey();
? ? ? ? }
? ? }
}

運行

案例2

json

{
?? ?"ID": 1,
?? ?"Name": "張三",
?? ?"Favorites": ["吃飯", "睡覺"]
}

代碼

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
?
namespace JObject案例
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? string json = "{\"ID\":1,\"Name\":\"張三\",\"Favorites\":[\"吃飯\",\"睡覺\"]}";
? ? ? ? ? ? JObject jObject1 = JObject.Parse(json);
?
? ? ? ? ? ? Console.WriteLine(jObject1["ID"]);
? ? ? ? ? ? Console.WriteLine(jObject1["Name"]);
? ? ? ? ? ? Console.WriteLine(jObject1["Favorites"][0]);
? ? ? ? ? ? Console.WriteLine(jObject1["Favorites"][1]);
?
? ? ? ? ? ? Console.ReadKey();
? ? ? ? }
? ? }
}

運行

案例3

json

{
?? ?"input": {
?? ??? ?"size": 193156,
?? ??? ?"type": "image/png"
?? ?},
?? ?"output": {
?? ??? ?"size": 59646,
?? ??? ?"type": "image/png",
?? ??? ?"width": 487,
?? ??? ?"height": 284,
?? ??? ?"ratio": 0.3088,
?? ??? ?"url": "https://www.baidu.com"
?? ?}
}

代碼

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Text;
?
namespace JObject案例
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? string json = "{\"input\":{\"size\":193156,\"type\":\"image/png\"},\"output\":{\"size\":59646,\"type\":\"image/png\",\"width\":487,\"height\":284,\"ratio\":0.3088,\"url\":\"https://www.baidu.com\"}}";
? ? ? ? ? ? JObject jObject1 = JObject.Parse(json);
?
? ? ? ? ? ? Console.WriteLine(jObject1["input"]["size"]);
? ? ? ? ? ? Console.WriteLine(jObject1["input"]["type"]);
? ? ? ? ? ? Console.WriteLine(jObject1["output"]["size"]);
? ? ? ? ? ? Console.WriteLine(jObject1["output"]["type"]);
?
? ? ? ? ? ? Console.ReadKey();
? ? ? ? }
? ? }
}

運行

案例4

json

{
?? ?"code": "SUCCESS",
?? ?"msg": null,
?? ?"data": [{
?? ??? ?"id": 31783735,
?? ??? ?"residentInfoId": 2000099151,
?? ??? ?"doctorId": "89bd0716-f916-4e51-93f7-4d416830f03c"
?? ?}]
}

代碼

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Text;
?
namespace JObject案例
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? string json = "{\"code\":\"SUCCESS\",\"msg\":null,\"data\":[{\"id\":31783735,\"residentInfoId\":2000099151,\"doctorId\":\"89bd0716-f916-4e51-93f7-4d416830f03c\"}]}";
? ? ? ? ? ? JObject jObject1 = JObject.Parse(json);
?
? ? ? ? ? ? Console.WriteLine(jObject1["code"]);
? ? ? ? ? ? Console.WriteLine(jObject1["SUCCESS"]);
? ? ? ? ? ? Console.WriteLine(jObject1["data"][0]["id"]);
? ? ? ? ? ? Console.WriteLine(jObject1["data"][0]["residentInfoId"]);
? ? ? ? ? ? Console.WriteLine(jObject1["data"][0]["doctorId"]);
?
? ? ? ? ? ? Console.ReadKey();
? ? ? ? }
? ? }
}

運行

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內(nèi)容請查看下面相關鏈接

相關文章

  • C#對Access進行增刪改查的完整示例

    C#對Access進行增刪改查的完整示例

    本文主要是講C#對Access數(shù)據(jù)庫的增刪改查操作,想學習C#和Access數(shù)據(jù)庫操作基礎的可以參考借鑒,以下代碼都經(jīng)過實踐測試可用,下面跟著小編一起來看看。
    2016-08-08
  • C#判斷一個矩陣是否為對稱矩陣及反稱矩陣的方法

    C#判斷一個矩陣是否為對稱矩陣及反稱矩陣的方法

    這篇文章主要介紹了C#判斷一個矩陣是否為對稱矩陣及反稱矩陣的方法,涉及C#矩陣遍歷及檢查等相關運算技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-08-08
  • C#讀取txt文件數(shù)據(jù)的方法實例

    C#讀取txt文件數(shù)據(jù)的方法實例

    讀取txt文本數(shù)據(jù)的內(nèi)容,是我們開發(fā)中經(jīng)常會遇到的一個功能,這篇文章主要給大家介紹了關于C#讀取txt文件數(shù)據(jù)的相關資料,需要的朋友可以參考下
    2021-05-05
  • C#延時函數(shù)的使用說明

    C#延時函數(shù)的使用說明

    這篇文章主要介紹了C#延時函數(shù)的使用說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • C#實現(xiàn)簡單串口通信的示例詳解

    C#實現(xiàn)簡單串口通信的示例詳解

    這篇文章主要為大家詳細介紹了C#實現(xiàn)串口通信的相關知識,文中示例代碼介紹的非常詳細,具有一定的學習價值,感興趣的小伙伴們可以跟隨小編一起了解一下
    2023-10-10
  • C#獲取硬盤編號的方法

    C#獲取硬盤編號的方法

    這篇文章主要介紹了C#獲取硬盤編號的方法,涉及C#獲取硬件屬性的相關技巧,非常簡單實用,需要的朋友可以參考下
    2015-05-05
  • C#使用Shader實現(xiàn)夜幕降臨倒計時的效果

    C#使用Shader實現(xiàn)夜幕降臨倒計時的效果

    這篇文章主要介紹了C#使用Shader實現(xiàn)夜幕降臨倒計時的效果,非常不錯具有參考借鑒價值,需要的朋友可以參考下
    2016-10-10
  • c#日期間隔計算示例

    c#日期間隔計算示例

    這篇文章主要介紹了c#日期間隔計算類,最后有使用方法,需要的朋友可以參考下
    2014-02-02
  • C#詞法分析器之輸入緩沖和代碼定位的應用分析

    C#詞法分析器之輸入緩沖和代碼定位的應用分析

    本篇文章介紹了,C#詞法分析器之輸入緩沖和代碼定位的應用分析。需要的朋友參考下
    2013-05-05
  • C#中后臺post請求常用的兩種方式總結

    C#中后臺post請求常用的兩種方式總結

    這篇文章主要介紹了C#中后臺post請求常用的兩種方式總結,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06

最新評論

铜梁县| 青浦区| 铅山县| 普定县| 敦化市| 奈曼旗| 景谷| 兴宁市| 墨脱县| 宜丰县| 铁力市| 宜州市| 扎赉特旗| 武山县| 延寿县| 会昌县| 龙州县| 阿图什市| 北海市| 崇信县| 喀喇| 迁安市| 都江堰市| 化德县| 武威市| 柘荣县| 定兴县| 汉沽区| 宾阳县| 南溪县| 永平县| 马关县| 特克斯县| 泸水县| 苍梧县| 枣阳市| 屏南县| 象山县| 木兰县| 阿克苏市| 渭源县|