<!-- generator=" CodePongo (Base on Kukkaisvoima version 15b3TA)" -->
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<channel><title>CodePongo: json</title><link>http://codepongo.com/blog</link><description></description><pubDate>Fri, 16 Dec 2016 17:30:06 +0200</pubDate><lastBuildDate>Fri, 16 Dec 2016 17:30:06 +0200</lastBuildDate><generator>http://codepongo.com/blog</generator><language>zh-cn</language><item><title>zanders3json
</title><link>http://codepongo.com/blog/4PGhBT</link><comments>http://codepongo.com/blog/4PGhBT#comments</comments><pubDate>Fri, 16 Dec 2016 17:30:06 +0200</pubDate><dc:creator>zuohaitao</dc:creator><category>json</category><category>CSharp</category><guid isPermaLink="false">http://codepongo.com/blog/4PGhBT/</guid><description><![CDATA[ 
 [...]]]></description><content:encoded><![CDATA[
https://github.com/zanders3/json是一个C#实现的json库，只有几百行代码，为了简便牺牲了效率（No JIT Emit support to parse structures quickly）。

接口


将json字符串解析成c#中的T类型



T TinyJson.JSONParser.FromJson(this string json)



将C#的object导出成json格式的字符串



string TinyJson.JSONWriter.ToJson(this object item)


json结构与C#的对应关系


object应设为c#中的dictionary&lt;string,object&gt;或object；
array映射为ArrayList；number映射为int，float或double；
string还是string；boolean还是boolean。


实现思路

如果是基本数据类型则直接返回，如果是容器类型则以递归的方式根据不同类型调用不同方法进行解析和序列化。

示例


using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using TinyJson;
namespace TinyJsonTester
{
    class Program
    {
        static void Main(string[] args)
        {
            object json = new Dictionary
            {
                {"string", "" },
                {"number", new Dictionary {
                                {"int",0 },
                                {"float", 0.1f },
                                {"double", 0.0001 }
                            }
                },
                {"array", new ArrayList {
                                    0,
                                    "0",
                                    null,
                                    true
                                }
                }
            };
            string jsonText = JSONWriter.ToJson(json);
            Console.WriteLine(jsonText);
 (jsonText);
            string stringValue = (string)root["string"];
            //Dictionary number = (Dictionary)root["number"];
            float f = (float)(double)((Dictionary)root["number"])["float"];
            //List array = (List)root["array"];
            int zero = (int)(((List)root["array"])[0]);
            Console.WriteLine($"{root}, {stringValue}, {f} , {zero}");
        }
    }
}


]]></content:encoded><wfw:commentRss>http://codepongo.com/blog/4PGhBT/feed/</wfw:commentRss></item></channel></rss>