1. //先在项目中添加System.Web.Extensions引用
    2. using System.Web.Script.Serialization;
    3. JavaScriptSerializer serializer = new JavaScriptSerializer();
    4. Dictionary<stringobject> json = (Dictionary<stringobject>)serializer.DeserializeObject(
    5.     "{name: 'xrend', forum: 'c#'}");
    6. object value;
    7. if (json.TryGetValue("name"out value))
    8.     Console.WriteLine(value);

这样,我们就可以把json数据解析读取了 简单吧 ~~


2013-10-15 修改,

看到自己之前写的这篇文章,简直删的心思都有了,太弱了,为了不把大家带到沟里,5年后的我用的 newtonsoft.json.dll这个第三方工具来解析的,两个方法就足够用了

 public static T DeserializeObject<T>(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(value);
            }
            else
            {
                return default(T);
            }
        }

        public static string JsonSerializer(object obj)
        {
            IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
            timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss";
            return Newtonsoft.Json.JsonConvert.SerializeObject(obj,Newtonsoft.Json.Formatting.None,timeConverter);
        }
由于自己解析的日期格式是 国际标准时间,带时区的,加上这个日期格式的转换,就可以解析自己想要的日期字符串了

GitHub 加速计划 / js / json
18
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:3 个月前 )
2134cb94 * change NLOHMANN_JSON_FROM_WITH_DEFAULT to let NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT work with an empty JSON instance * fix ci_static_analysis_clang (ci_clang_tidy) * change NLOHMANN_JSON_FROM_WITH_DEFAULT to let NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT work with an empty JSON instance 5 天前
6057b31d * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * Use ubuntu-latest image to run Valgrind (#4575) * :wrench: use Clang image to run valgrind * :wrench: use Clang image to run valgrind * :wrench: use Clang image to run valgrind * :wrench: use Ubuntu image to run valgrind * Use Clang image to run iwyu (#4574) * :wrench: use Clang image to run iwyu * :wrench: use Clang image to run iwyu * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :art: format code * :hammer: clean up 6 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐