C# hashtable 转json
来源:互联网 发布:pp助手mac版铃声 编辑:程序博客网 时间:2024/06/05 20:41
以前常常码php, 换成C#就习惯用hashtable当数php数组代替,而生成json不想用json.net dll 只能自个写了,
hashtable hr=new hashtable();
hr.add("name","pan");
hr.add("die","True");
hashtable log=new hashtable();
log.add("1","sdfsdfsdf");
log.add("2","delete user");
hr.add("log",log);
public static string HashtableToJson(Hashtable hr,int readcount=0)
{string json="{";
foreach(DictionaryEntry row in hr)
{
try
{
string key = "\"" + row.Key + "\":";
if (row.Value is Hashtable)
{
Hashtable t = (Hashtable)row.Value;
if(t.Count>0)
{
json += key + HashtableToJson(t, readcount++)+",";
}
else { json += key + "{},"; }
}
else
{
string value = "\"" + row.Value.ToString() + "\",";
json += key + value;
}
}
catch { }
}
// json = MyString.ClearEndChar(json);
json = json + "}";
return json;
}
0 0
- C# hashtable 转json
- Unity3D开发之Hashtable转Json
- C# HashTable
- C# Hashtable
- C# Hashtable
- C# hashtable
- C# Hashtable
- C# Hashtable
- C# HashTable
- c# hashtable
- C# Hashtable
- C# 、HashTable
- C# Hashtable
- C# Hashtable
- C# Hashtable 使用说明 以及 Hashtable和HashMap的区别[转]
- (转)C#中HashTable的使用
- ArrayList、HashTable到JSON
- C# List转Json
- Hibernate 入门简介
- 在Android上使用tcpdump抓包
- Tomcat免安装版My eclipse配置步骤
- C# 枚举类型另类用法
- 黑马程序员_JAVA 学习笔记15 WEB篇2
- C# hashtable 转json
- hadoop中使用MapReduce编程实例(转)
- Java Socket常见异常处理
- JavaScript cookie详解
- 为什么选安卓不选IOS-兼谈安卓为什么慢和耗电
- 黑马程序员_JAVA 学习笔记16 WEB篇3
- Linux- 内核引导过程
- FullCalendar应用——整合农历节气和节日
- 黑马程序员_简谈java