资源简介
c#版本的校验文本是否为合法json格式,单独一个类无需其他引用

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CheckJSON
{
internal class JsonSplit
{
private static bool IsJsonstart(ref string json)
{
if (!string.IsNullOrEmpty(json))
{
json = json.Trim(‘\r‘ ‘\n‘ ‘ ‘);
if (json.Length > 1)
{
char s = json[0];
char e = json[json.Length - 1];
return (s == ‘{‘ && e == ‘}‘) || (s == ‘[‘ && e == ‘]‘);
}
}
return false;
}
internal static bool IsJson(string json)
{
int errIndex;
return IsJson(json out errIndex);
}
internal static bool IsJson(string json out int errIndex)
{
errIndex = 0;
if (IsJsonstart(ref json))
{
CharState cs = new CharState();
char c;
for (int i = 0; i < json.Length; i++)
{
c = json[i];
if (SetCharState(c ref cs) && cs.childrenStart)//设置关键符号状态。
{
string item = json.Substring(i);
int err;
int length = GetValueLength(item true out err);
cs.childrenStart = false;
if (err > 0)
{
errIndex = i + err;
return false;
}
i = i + length - 1;
}
if (cs.isError)
{
errIndex = i;
return false;
}
}
return !cs.arrayStart && !cs.jsonstart;
}
return false;
}
///
/// 获取值的长度(当Json值嵌套以“{“或“[“开头时)
///
private static int GetValueLength(string json bool breakOnErr out int errIndex)
{
errIndex = 0;
int len = 0;
if (!string.IsNullOrEmpty(json))
{
CharState cs = new CharState();
char c;
for (int i = 0; i < json.Length; i++)
{
c = json[i];
if (!SetCharState(c ref cs))//设置关键符号状态。
{
if (!cs.jsonstart && !cs.arrayStart)//json结束,又不是数组,则退出。
{
break;
}
}
else if (cs.childrenStart)//正常字符,值状态下。
{
int length = GetValueLength(json.Substring(i) breakOnErr out errIndex);//递归子值,返回一个长度。。。
cs.childrenStart = fa
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 12288 2015-08-28 16:11 CheckJSON\CheckJSON\bin\Debug\CheckJSON.exe
文件 32256 2015-08-28 16:11 CheckJSON\CheckJSON\bin\Debug\CheckJSON.pdb
文件 22472 2015-08-31 08:53 CheckJSON\CheckJSON\bin\Debug\CheckJSON.vshost.exe
文件 490 2012-06-06 02:06 CheckJSON\CheckJSON\bin\Debug\CheckJSON.vshost.exe.manifest
文件 3768 2015-08-28 14:12 CheckJSON\CheckJSON\CheckJSON.csproj
文件 16252 2015-08-28 14:12 CheckJSON\CheckJSON\Class1.cs
文件 1107 2015-08-28 16:11 CheckJSON\CheckJSON\Form1.cs
文件 2022 2015-08-28 14:12 CheckJSON\CheckJSON\Form1.Designer.cs
文件 5817 2015-08-28 14:12 CheckJSON\CheckJSON\Form1.resx
文件 882 2015-08-31 08:53 CheckJSON\CheckJSON\obj\Debug\CheckJSON.csproj.FileListAbsolute.txt
文件 975 2015-08-28 16:10 CheckJSON\CheckJSON\obj\Debug\CheckJSON.csproj.GenerateResource.Cache
文件 2209 2015-08-28 16:10 CheckJSON\CheckJSON\obj\Debug\CheckJSON.csprojResolveAssemblyReference.cache
文件 12288 2015-08-28 16:11 CheckJSON\CheckJSON\obj\Debug\CheckJSON.exe
文件 180 2015-08-28 16:10 CheckJSON\CheckJSON\obj\Debug\CheckJSON.Form1.resources
文件 32256 2015-08-28 16:11 CheckJSON\CheckJSON\obj\Debug\CheckJSON.pdb
文件 180 2015-08-28 16:10 CheckJSON\CheckJSON\obj\Debug\CheckJSON.Properties.Resources.resources
文件 1451 2015-08-31 08:53 CheckJSON\CheckJSON\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6905 2015-08-28 14:11 CheckJSON\CheckJSON\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 490 2015-08-28 14:05 CheckJSON\CheckJSON\Program.cs
文件 1338 2015-08-28 14:05 CheckJSON\CheckJSON\Properties\AssemblyInfo.cs
文件 2870 2015-08-28 14:05 CheckJSON\CheckJSON\Properties\Resources.Designer.cs
文件 5612 2015-08-28 14:05 CheckJSON\CheckJSON\Properties\Resources.resx
文件 1096 2015-08-28 14:05 CheckJSON\CheckJSON\Properties\Settings.Designer.cs
文件 249 2015-08-28 14:05 CheckJSON\CheckJSON\Properties\Settings.settings
文件 917 2015-08-28 14:05 CheckJSON\CheckJSON.sln
..A..H. 331264 2015-08-31 08:58 CheckJSON\CheckJSON.v11.suo
目录 0 2015-08-28 14:05 CheckJSON\CheckJSON\obj\Debug\TempPE
目录 0 2015-08-28 16:10 CheckJSON\CheckJSON\bin\Debug
目录 0 2015-08-31 08:53 CheckJSON\CheckJSON\obj\Debug
目录 0 2015-08-28 14:05 CheckJSON\CheckJSON\bin
............此处省略7个文件信息
- 上一篇:杜洋入门C#设计视频资料
- 下一篇:C#访问共享文件夹
相关资源
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
- C# 使用ListView控件实现图片浏览器(源
- C#简单窗体聊天程序
- C#指纹识别系统程序 报告
- c# 高校档案信息管理系统
- c#向word文件插入图片
- C#左侧导航菜单(动态生成)
- C#TCP 通信(TCP发送16进制)
- C# sql实现批量导入数据到数据库
评论
共有 条评论