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
        }
    }
}
相关推荐
莫爷1 天前
JSON 进阶技巧:Schema 验证、JSONPath 查询、性能优化
性能优化·json
莫爷1 天前
JSON vs XML vs YAML 深度对比:如何选择合适的数据格式?
xml·前端·json
ZTLJQ1 天前
序列化的艺术:Python JSON处理完全解析
开发语言·python·json
CSharp精选营2 天前
.NET对象转JSON,到底有几种方式?
c#·json·.net·newtonsoft·对象转换·utf8json
淼_@淼2 天前
python-json
前端·python·json
Bear on Toilet2 天前
HTTP + JSON 接口调用清单总结
网络协议·http·json
电商API&Tina3 天前
【电商API接口】开发者一站式电商API接入说明
大数据·数据库·人工智能·云计算·json
消失的旧时光-19433 天前
Android 面试高频:JSON 文件、大数据存储与断电安全(从原理到工程实践)
android·面试·json
ChoSeitaku3 天前
NO.4|protobuf网络版通讯录|httplib|JSON、XML、ProtoBuf对比
xml·json
青衫客363 天前
浅谈 Java 后端对象映射:从 JSON → VO → Entity 的原理与实践
java·json