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
        }
    }
}
相关推荐
jieyucx15 小时前
Go 语言 JSON 序列化与反序列化
开发语言·golang·json·序列化
xwjalyf16 小时前
javascript数组 forEach,filter,some,every,map,find,reduce的用法与区别
开发语言·javascript·json·ecmascript
吾爱测试17 小时前
LZCCB_CREDIT_DEMO.json
json
明月_清风2 天前
文本序列化格式全景——JSON、XML、YAML 的适用边界与选型
后端·json
明月_清风2 天前
为什么需要序列化?——从内存对象到字节流,理解数据交换的本质
后端·json
ZC跨境爬虫2 天前
模块化烹饪小程序开发日记 Day7:(菜谱详情接口开发与JSON数据读取全流程)
前端·javascript·css·ui·微信小程序·json
alwaysrun3 天前
C++之现代易用JSON库nlohmann
c++·json·序列化·nlohmann
lifejump4 天前
JSON技术解析
json