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
        }
    }
}
相关推荐
IDIOT___IDIOT15 小时前
JSON-RPC 2.0 与 MCP 协议:从消息格式到进程通信 大模型MCP
rpc·大模型·json·agent·mcp
憧憬成为原神糕手17 小时前
Playwright、Selenium、DrissionPage 与 JSON 接口怎么选?
数据库·selenium·json
SelectDB技术团队17 小时前
Apache Doris 4.1:面向 AI & Search 的统一数据底座怎么选?向量检索 + 全文搜索 + 100MB JSON 完整能力拆解
人工智能·json·apache doris
进击切图仔19 小时前
VS Code 调试 launch.json 解析
json
码智社1 天前
JSON 零基础到资深全体系教程
java·json
五阿哥永琪2 天前
MySQL中操作json的函数!
数据库·mysql·json
用户7783366132113 天前
SERP API JSON Schema 演进版本管理实战
json·api
IT小盘4 天前
14-让大模型稳定输出JSON-Prompt约束与结构化输出
windows·json·prompt
赵庆明老师4 天前
Vben精讲:21-详解web-antd:tsconfig.json
前端·json·vim
红叶舞6 天前
成数据绑定对象,在应用程序中处理完数据后,将更新的数据序列化为JSON传回远端服务器,很多移动应用使用了这种模式处理服务器端的数据。 ...
运维·服务器·json