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
        }
    }
}
相关推荐
愤怒的苹果ext1 天前
MySQL JSON查询与索引
mysql·json·虚拟列·多值索引
dcloud_jibinbin1 天前
【uniapp】解决小程序分包下的json文件编译后生成到主包的问题
前端·性能优化·微信小程序·uni-app·vue·json
Jonathan Star2 天前
Vue JSON结构编辑器组件设计与实现解析
vue.js·编辑器·json
工业甲酰苯胺4 天前
实现 json path 来评估函数式解析器的损耗
java·前端·json
optimistic_chen4 天前
【Java EE进阶 --- SpringBoot】统一功能处理
java·spring boot·java-ee·json·统一功能处理
Momentary_SixthSense5 天前
serde
开发语言·rust·json
MediaTea5 天前
Python 文件操作:JSON 格式
开发语言·windows·python·json
ejinxian5 天前
protobuf 、JSON、XML传输格式
xml·json·protobuf
zhougl9966 天前
cookie、session、token、JWT(JSON Web Token)
前端·json
人工智能的苟富贵6 天前
用 Rust 写一个前端项目辅助工具:JSON 格式化器
前端·rust·json