欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#使用Newtonsoft.Json中的JObject對(duì)象

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

案例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();
? ? ? ? }
? ? }
}

運(yùn)行

案例2

json

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

代碼

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
?
namespace JObject案例
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? string json = "{\"ID\":1,\"Name\":\"張三\",\"Favorites\":[\"吃飯\",\"睡覺(jué)\"]}";
? ? ? ? ? ? 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();
? ? ? ? }
? ? }
}

運(yùn)行

案例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();
? ? ? ? }
? ? }
}

運(yùn)行

案例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();
? ? ? ? }
? ? }
}

運(yùn)行

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接

相關(guān)文章

  • 使用WPF實(shí)現(xiàn)一個(gè)虛擬鍵盤(pán)的代碼示例

    使用WPF實(shí)現(xiàn)一個(gè)虛擬鍵盤(pán)的代碼示例

    在某些特定場(chǎng)景下,我們可能需要使用虛擬鍵盤(pán)來(lái)替代實(shí)體鍵盤(pán),本文將詳細(xì)介紹如何使用 WPF 來(lái)實(shí)現(xiàn)一個(gè)虛擬鍵盤(pán),并監(jiān)控鍵盤(pán)輸入,從而達(dá)到完全替代實(shí)體鍵盤(pán)的目的,需要的朋友可以參考下
    2025-04-04
  • c#自帶緩存使用方法 c#移除清理緩存

    c#自帶緩存使用方法 c#移除清理緩存

    這篇文章主要介紹了c#自帶緩存使用方法,包括獲取數(shù)據(jù)緩存、設(shè)置數(shù)據(jù)緩存、移除指定數(shù)據(jù)緩存等方法,需要的朋友可以參考下
    2014-02-02
  • C#使用DevExpress中的XtraCharts控件實(shí)現(xiàn)圖表

    C#使用DevExpress中的XtraCharts控件實(shí)現(xiàn)圖表

    這篇文章介紹了C#使用DevExpress中的XtraCharts控件實(shí)現(xiàn)圖表的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • 在C#中添加I/O延時(shí)和持續(xù)時(shí)間的實(shí)現(xiàn)方法

    在C#中添加I/O延時(shí)和持續(xù)時(shí)間的實(shí)現(xiàn)方法

    這篇文章主要介紹了在C#中添加I/O延時(shí)和持續(xù)時(shí)間的實(shí)現(xiàn)方法,文中有相關(guān)的代碼示例供大家參考,對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2025-01-01
  • C#實(shí)現(xiàn)將PDF轉(zhuǎn)為線(xiàn)性化PDF

    C#實(shí)現(xiàn)將PDF轉(zhuǎn)為線(xiàn)性化PDF

    線(xiàn)性化PDF文件是PDF文件的一種特殊格式,可以通過(guò)Internet更快地進(jìn)行查看。這篇文章主要介紹了如何通過(guò)C#實(shí)現(xiàn)將PDF轉(zhuǎn)為線(xiàn)性化PDF,感興趣的小伙伴可以學(xué)習(xí)一下
    2021-12-12
  • C#使用NPOI將excel導(dǎo)入到list的方法

    C#使用NPOI將excel導(dǎo)入到list的方法

    這篇文章主要為大家詳細(xì)介紹了C#使用NPOI將excel導(dǎo)入到list的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • c#中合并excel表格的方法示例

    c#中合并excel表格的方法示例

    本篇文章主要介紹了c#中合并excel表格的方法,就是將excel表格結(jié)構(gòu)一樣的合并到一起,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2016-10-10
  • c#如何獲取json數(shù)組里指定參數(shù)

    c#如何獲取json數(shù)組里指定參數(shù)

    這篇文章主要介紹了c#如何獲取json數(shù)組里指定參數(shù)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • C#獲取本機(jī)IP地址和Mac地址的方法

    C#獲取本機(jī)IP地址和Mac地址的方法

    這篇文章主要介紹了C#獲取本機(jī)IP地址和Mac地址的方法,實(shí)例分析了C#網(wǎng)絡(luò)功能的基本技巧,需要的朋友可以參考下
    2015-05-05
  • C#中ref和out的區(qū)別淺析

    C#中ref和out的區(qū)別淺析

    這篇文章主要介紹了C#中ref和out的區(qū)別淺析,當(dāng)一個(gè)方法需要返回多個(gè)值的時(shí)候,就需要用到ref和out,那么這兩個(gè)方法區(qū)別在哪兒呢,需要的朋友可以參考下
    2015-01-01

最新評(píng)論