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
        }
    }
}
相关推荐
麻瓜code17 小时前
流式返回的工具参数是一段一段来的,怎么拼成一个 JSON
json
鲸渔3 天前
【AI Agent系列课程13-Python 基础13】JSON 读写:结构化数据交换基础
开发语言·python·json·ai编程
aiotto资源分享6 天前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
一起学安全技术6 天前
拆大模型 10|结构化输出:让模型返回数据,而不是一段话
人工智能·语言模型·json
用户298698530147 天前
在 Python 中把 Word 文档转换为 JSON 的三种实现方式
python·json·api
FRing039 天前
vue2干货总结10(json-server、vant-ui、postcss插件、axios二次封装、图形验证码、toast轻提示)
开发语言·前端·vue.js·ui·json·vue2·postcss
用户298698530149 天前
使用 Python 将 JSON 转换为 Word 文档的实践指南
python·json·api
九英里路9 天前
protobuf快速上手
网络·c++·中间件·json·谷歌·序列化·protobuf
wuyk55510 天前
Spider-第09讲-三格式落盘CSV-Excel-JSON
爬虫·python·json·excel
wuyk55511 天前
Spider-第07讲-JSON接口与正则提取
爬虫·python·json