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
        }
    }
}
相关推荐
原来是猿19 小时前
JSON 序列化与反序列化 —— 用 Jsoncpp 打造自己的网络协议
网络·网络协议·json
愈努力俞幸运1 天前
json schema
json
神所夸赞的夏天2 天前
如何获取多层json数据,存成dictionary,并取最大最小值
java·前端·json
web3.08889992 天前
天猫API接口详解:商品详情与关键词搜索商品指南及代码示例
python·json
老神在在0013 天前
jsonshema小点
python·json
阿Y加油吧4 天前
RAG 必学:ANN 检索、HNSW 算法与 Milvus 核心概念详解
数据库·mysql·json
likerhood4 天前
Fastjson中的JSON.parseObject()详细讲解
java·json
老神在在0015 天前
JSON Schema
测试工具·json
xiaodaoluanzha5 天前
golang中MetaMessage(mm)的使用
json·protobuf
星空椰6 天前
从零到实战:一套完整的 Python 爬虫技术体系(requests + BeautifulSoup + 正则 + JSON)
爬虫·python·json·beautifulsoup