ASPNET万能JSON解析器Word文档下载推荐.docx

上传人:b****3 文档编号:15898236 上传时间:2022-11-16 格式:DOCX 页数:10 大小:16.55KB
下载 相关 举报
ASPNET万能JSON解析器Word文档下载推荐.docx_第1页
第1页 / 共10页
ASPNET万能JSON解析器Word文档下载推荐.docx_第2页
第2页 / 共10页
ASPNET万能JSON解析器Word文档下载推荐.docx_第3页
第3页 / 共10页
ASPNET万能JSON解析器Word文档下载推荐.docx_第4页
第4页 / 共10页
ASPNET万能JSON解析器Word文档下载推荐.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

ASPNET万能JSON解析器Word文档下载推荐.docx

《ASPNET万能JSON解析器Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《ASPNET万能JSON解析器Word文档下载推荐.docx(10页珍藏版)》请在冰豆网上搜索。

ASPNET万能JSON解析器Word文档下载推荐.docx

0,"

data"

377149574"

:

1}}

total是值,data是对象,这个对象包含了"

这个值,等于1

3.最复杂

[{"

cid"

"

}]}}

total是值,data是对象,377149574是数组,这个数组包含了一些列的对象,例如{"

}这个对象。

有了以上的概念,就可以设计出通用的json模型了。

万能JSON源码:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

namespacePixysoft.Json

{

 

publicclassCommonJsonModelAnalyzer

{

protectedstring_GetKey(stringrawjson)

if(string.IsNullOrEmpty(rawjson))

returnrawjson;

rawjson=rawjson.Trim();

string[]jsons=rawjson.Split(newchar[]{'

'

});

if(jsons.Length<

2)

returnjsons[0].Replace("

\"

"

).Trim();

}

protectedstring_GetValue(stringrawjson)

},StringSplitOptions.RemoveEmptyEntries);

StringBuilderbuilder=newStringBuilder();

for(inti=1;

i<

jsons.Length;

i++)

builder.Append(jsons[i]);

builder.Append("

);

if(builder.Length>

0)

builder.Remove(builder.Length-1,1);

stringvalue=builder.ToString();

if(value.StartsWith("

))

value=value.Substring

(1);

if(value.EndsWith("

value=value.Substring(0,value.Length-1);

returnvalue;

protectedList<

string>

_GetCollection(stringrawjson)

//[{},{}]

List<

list=newList<

();

returnlist;

intnestlevel=-1;

intmnestlevel=-1;

for(inti=0;

rawjson.Length;

if(i==0)

continue;

elseif(i==rawjson.Length-1)

charjsonchar=rawjson[i];

if(jsonchar=='

{'

nestlevel++;

}'

nestlevel--;

['

mnestlevel++;

]'

mnestlevel--;

'

&

&

nestlevel==-1&

mnestlevel==-1)

list.Add(builder.ToString());

builder=newStringBuilder();

else

builder.Append(jsonchar);

}

publicclassCommonJsonModel:

CommonJsonModelAnalyzer

privatestringrawjson;

privateboolisValue=false;

privateboolisModel=false;

privateboolisCollection=false;

internalCommonJsonModel(stringrawjson)

this.rawjson=rawjson;

thrownewException("

missingrawjson"

if(rawjson.StartsWith("

isModel=true;

elseif(rawjson.StartsWith("

["

isCollection=true;

isValue=true;

publicstringRawjson

get{returnrawjson;

publicboolIsValue()

returnisValue;

publicboolIsValue(stringkey)

if(!

isModel)

returnfalse;

if(string.IsNullOrEmpty(key))

foreach(stringsubjsoninbase._GetCollection(this.rawjson))

CommonJsonModelmodel=newCommonJsonModel(subjson);

model.IsValue())

if(model.Key==key)

CommonJsonMo

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 理化生

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1