c# 直接读取 json 数据

发布时间 2023-11-15 11:00:15作者: G月月鸟

using Newtonsoft.Json.Linq;
using System;
using System.IO;

class Program
{
static void Main()
{
string json = File.ReadAllText("data.json"); // 从文件中读取JSON数据

JObject jsonObject = JObject.Parse(json); // 解析JSON数据

string name = (string)jsonObject["Name"]; // 读取Name属性的值
int age = (int)jsonObject["Age"]; // 读取Age属性的值

Console.WriteLine($"Name: {name}");
Console.WriteLine($"Age: {age}");
}
}