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
        }
    }
}
相关推荐
wtsolutions20 分钟前
JSON导入WPS表格,JSON转wps,json2wps, WPS 插件使用指南
json·wps·wtsolutions
ewboYang1 小时前
JSON.parse()大整数精度丢失的问题和解决方法
json
wtsolutions5 小时前
WPS另存为JSON,WPS导出JSON, WPS表格转换成JSON : Excel to JSON WPS插件使用指南
json·excel·wps·插件·加载项·wtsolutions
czlczl200209255 小时前
从抛出异常到返回 JSON/XML:SpringBoot 异常处理全链路解析
xml·spring boot·json
莫叫石榴姐6 小时前
如何让大模型更好地理解和处理 JSON 数据?
语言模型·json
MarkHD7 小时前
车辆TBOX科普 第51次 WebSocket实时通信与数据序列化:JSON vs Protobuf的深度实践
websocket·网络协议·json
qq_3280678117 小时前
springboot4 启动 Unable to find JSON tool
spring boot·json
踏浪无痕1 天前
你真的懂泛型吗?手写 MyBatis-Plus + Jackson,揭秘框架设计的精髓
后端·json·mybatis
Appreciate(欣赏)1 天前
Spark解析JSON字符串
大数据·spark·json
wtsolutions1 天前
JSON转Excel工具新增WPS插件功能,将JSON转换成WPS表格工作表数据
json·excel·wps·插件·转换·加载项·wtsolutions