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
        }
    }
}
相关推荐
蓝悦无人机8 小时前
LangChain v1.0 系列教程——第2章 工具系统
langchain·json·装饰器模式·pydantic
Lyra_Infra12 小时前
从一段错误 JSON 说起:Policy、Role 与 IAM
后端·json·aigc
羑悻的小杀马特13 小时前
数据织网者:Jsoncpp库深度解析——从C++原生JSON处理到工程级数据交互实战全攻略
c++·json·交互·jsoncpp·原生库
代码什么用13 小时前
JSON一文速通
java·json
小小测试开发1 天前
LLM 结构化输出测试:Schema 契约 + 故障注入,让工具调用的 JSON 不再靠重试赌运气
人工智能·json
hasty1 天前
_proto__ 不是普通键:从 JSON 反序列化看原型污染
安全·json
代码中介商1 天前
JSON 完全指南:从语法到项目实战
json
名字还没想好☜2 天前
Go 用 json.Decoder 流式解析大 JSON:边读边处理不爆内存
开发语言·后端·golang·go·json
gf13211112 天前
【python_发送飞书卡片消息_直接组装JSON格式发送卡片】
python·json·飞书
有梦想的咕噜2 天前
Newtonsoft.Json (Json.NET) 常用方法汇总
linux·json·.net