C#2010 .NET4 解析 json 字符串

下载Newtonsoft.Json.dll

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string jsonString = "{\"name\":\"Alice\",\"age\":25}";
            JObject jsonObject = JObject.Parse(jsonString);

            string name = jsonObject["name"].ToString();
            name = jsonObject.Value<string>("name");
            int age = jsonObject.Value<int>("age");

            Console.WriteLine("Name: " + name);  // 输出:Name: Alice
            Console.WriteLine("Age: " + age);  // 输出:Age: 25
        }
    }
}
相关推荐
Sylvia33.2 小时前
网球/羽毛球数据API:专业赛事数据服务的技术实现
java·前端·websocket·json
Watermelo6174 小时前
面向大模型开发:在项目中使用 TOON 的实践与流式处理
javascript·数据结构·人工智能·语言模型·自然语言处理·数据挖掘·json
时光慢煮4 小时前
基于 Flutter × OpenHarmony 开发的 JSON 解析工具实践
flutter·json
wtsolutions1 天前
Understanding Excel Data Formats - What Excel to JSON Supports
ui·json·excel
wtsolutions1 天前
Real-World Use Cases - How Organizations Use Excel to JSON
json·github·excel
cab51 天前
MyBatis如何处理数据库中的JSON字段
数据库·json·mybatis
FITA阿泽要努力1 天前
动手体验:5min实现第一个智能体——1
json·api·agent·requests·查询天气·pprint·f-string
wtsolutions1 天前
Using the Excel to JSON API - Programmatic Access for Developers
ui·json·xhtml
石云升1 天前
Claude Code 配置教程:如何通过修改 settings.json 优化 AI 编程体验
人工智能·json