国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net 2.0里也可以用JSON的使用方法

2024-07-10 12:42:25
字體:
來源:轉載
供稿:網友
全部代碼如下。 
代碼如下:
/// <summary>
/// JSON解析類
/// </summary>
public static class JSONConvert
{
#region 全局變量

private static JSONObject _json = new JSONObject();//寄存器
private static readonly string _SEMICOLON = "@semicolon";//分號轉義符
private static readonly string _COMMA = "@comma"; //逗號轉義符

#endregion

#region 字符串轉義
/// <summary>
/// 字符串轉義,將雙引號內的:和,分別轉成_SEMICOLON和_COMMA
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
private static string StrEncode(string text)
{
MatchCollection matches = Regex.Matches(text, "http:///"[^///"]+///"");
foreach (Match match in matches)
{
text = text.Replace(match.Value, match.Value.Replace(":", _SEMICOLON).Replace(",", _COMMA));
}

return text;
}

/// <summary>
/// 字符串轉義,將_SEMICOLON和_COMMA分別轉成:和,
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
private static string StrDecode(string text)
{
return text.Replace(_SEMICOLON, ":").Replace(_COMMA, ",");
}

#endregion

#region JSON最小單元解析

/// <summary>
/// 最小對象轉為JSONObject
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
private static JSONObject DeserializeSingletonObject(string text)
{
JSONObject jsonObject = new JSONObject();

MatchCollection matches = Regex.Matches(text, "(///"(?<key>[^///"]+)///":///"(?<value>[^,///"]+)///")|(///"(?<key>[^///"]+)///":(?<value>[^,///"http://}]+))");
foreach (Match match in matches)
{
string value = match.Groups["value"].Value;
jsonObject.Add(match.Groups["key"].Value, _json.ContainsKey(value) ? _json[value] : StrDecode(value));
}

return jsonObject;
}

/// <summary>
/// 最小數組轉為JSONArray
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
private static JSONArray DeserializeSingletonArray(string text)
{
JSONArray jsonArray = new JSONArray();

MatchCollection matches = Regex.Matches(text, "(///"(?<value>[^,///"]+)/")|(?<value>[^,//[//]]+)");
foreach (Match match in matches)
{
string value = match.Groups["value"].Value;
jsonArray.Add(_json.ContainsKey(value) ? _json[value] : StrDecode(value));
}

return jsonArray;
}

/// <summary>
/// 反序列化
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
private static string Deserialize(string text)
{
text = StrEncode(text);//轉義;和,

int count = 0;
string key = string.Empty;
string pattern = "(//{[^//[//]//{//}]+//})|(//[[^//[//]//{//}]+//])";
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大邑县| 蒙城县| 和田市| 娄烦县| 崇仁县| 陆良县| 孟津县| 顺昌县| 健康| 剑川县| 浏阳市| 杭锦后旗| 手游| 科技| 宁南县| 黄平县| 易门县| 咸丰县| 乳源| 延庆县| 永州市| 万载县| 华阴市| 青神县| 县级市| 奉节县| 宁强县| 新晃| 云和县| 息烽县| 乌兰察布市| 乐东| 义马市| 比如县| 新巴尔虎右旗| 苗栗市| 柳河县| 米林县| 分宜县| 明溪县| 乳源|