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
        }
    }
}
相关推荐
鬼手点金21 小时前
Scrapy + Playwright 完整示例(JS 动态渲染网页)
开发语言·javascript·爬虫·python·scrapy·html·json
AlfredZhao1 天前
VS Code 一键美化 JSON:不用安装插件
json
zhanghaha13141 天前
Python进阶教程:6_JSON 数据解析 —— 新手完全指南
开发语言·python·json
云水一下1 天前
零基础玩转bWAPP靶场(四十六):XSS - Reflected (AJAX/JSON)
web安全·ajax·json·xss·bwapp·reflected
小小龙学IT2 天前
simdjson:利用 SIMD 指令实现 GB/s 级 JSON 解析的 C++ 开源库
开发语言·c++·json
天吾cc2 天前
JSON 与 cJSON 学习笔记
笔记·学习·json
大家的林语冰2 天前
👍 JS 还在进化,ES2026 正式推出,最新七大特性补全!
前端·javascript·json
秋田君2 天前
QT_JSON文件操作
开发语言·qt·json
k4m7v2pz2 天前
Rust 规则热重载实战:用 serde_json + notify 告别重启
开发语言·rust·json·规则引擎·notify·热重载
灵析表格3 天前
json_ObjectToKV 函数:Excel解析JSON对象的权威方案
json·excel