Skip to main content
 首页 » 编程设计

c#之使用 JSON.NET 解析 JSON 数据

2024年08月06日33zhenyulu

有很多关于此的问题,但我找不到解决问题的方法。

我有如下所示的 JSON:

{ 
"index":[ 
  { 
     "Color":"Blue", 
     "URL":"SomeURL", 
 
     "Persons":[ 
        { 
           "name":"Charlie", 
           "Country":"Denmark", 
           "Security number":"25663456" 
        } 
     ], 
 
     "Color":"Green", 
     "URL":"SomeURL", 
 
     "Persons":[ 
        { 
           "name":"Putin", 
           "Country":"Russia", 
           "Security number":"78495832" 
         } 
       ], 
    ], 
  }  
 "total":"2" 
} 

我唯一可以访问的 JSON 数据是 index 和 total。

如何仅访问和打印出 name、Country 或 Color?

请您参考如下方法:

索引是一个数组。 index[0].Color 会给你“蓝色”等...