JSON解析新办法:JSEL

本文对比了三种JSON解析器:官方提供的org.json、StringTree及JSEL。StringTree以简洁高效著称,但不支持注释;JSEL除了标准JSON外还能处理注释和简单表达式。
JSON解析和系列化功能,JSON官方网站是提供了官方的Java实现的(org.json)。

但是,官方的实现并不理想。
不仅接口复杂的要命。而且效率也不理想,基本可以判定是一个不合格产品。

另外一个我比较喜欢的解析器,叫做StringTree。
这个解析器最大的特点就是简单,JSONReader负责解析,JSONWriter负责序列化,成员方法也简单明了。
他的输出格式除原始类型外,返回的Map,和List,充分利用了Java 集合框架。比起官方实现来,干净了很多。

StringTree不仅简单易用,而且性能也非常不错。
根据我的测试结果,StringTree最好。大概是JSEL的两倍。
而官方版本最差,大概只有是JSEL一半。等比数列了,[url=http://code.google.com/p/lite/wiki/JSEL]JSEL[/url]居中。

不过StringTree有一个bug,如果代码里面有注释,经常出现死循环。


再说[url=http://code.google.com/p/lite/wiki/JSEL]JSEL[/url]:
与专门的JSON解析相比,JSEL不仅可以解析标准的JSON数据,他还可以处理(忽略)JSON中插入的注释。甚至能处理一些简单的表达式计算,接口简单,性能也还不错。
如:

{
"time":24*60*60*1000*365*(2008-1981),
"data":[1,2,3,4,5],
key:123
}


关于JSEL的更多的信息可参看如下连接:
详细介绍:[url]http://code.google.com/p/lite/wiki/JSEL[/url]
详细介绍:[url]http://code.google.com/p/lite/downloads/list[/url]
10-15 15:43:40.318 40435-40435 A03D00/com.bds...ital.hm/JSAPP com.bdset...pital.hm I 健康管家------KYOcrPic 图片上传失败 {"message":"Request failed with status code 500","name":"AxiosError","stack":" at AxiosError (oh_modules/.ohpm/@ohos+axios@2.2.2/oh_modules/@ohos/axios/src/main/ets/components/lib/core/AxiosError.js:22:1)\n at settle (oh_modules/.ohpm/@ohos+axios@2.2.2/oh_modules/@ohos/axios/src/main/ets/components/lib/core/settle.js:19:1)\n at anonymous (oh_modules/.ohpm/@ohos+axios@2.2.2/oh_modules/@ohos/axios/src/main/ets/components/lib/adapters/ohos/upload.js:220:1)\n","config":{"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"adapter":["ohos"],"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"env":{"Blob":null},"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"multipart/form-data"},"context":{"__context_impl__":{"__base_context_ptr__":{},"applicationInfo":{"name":"com.bdsetyy.smarthospital.hm","bundleType":0,"debug":true,"description":"","descriptionId":0,"enabled":true,"label":"$string:app_name","labelId":16777228,"icon":"$media:bdsetyylogo_2","iconId":16777226,"process":"com.bdsetyy.smarthospital.hm","permissions":[],"entryDir":"","codePath":"/data/app/el1/bundle/public/com.bdsetyy.smarthospital.hm","metadata":{},"metadataArray":[],"removable":true,"accessTokenId":537423034,"uid":20020196,"iconResource":{"bundleName":"com.bdsetyy.smarthospital.hm","moduleName":"entry","id":16777226},"labelResource":{"bundleName":"com.bdsetyy.smarthospital.hm","moduleName":"entry","id":16777228},"descriptionResource":{"bundleName":"com.bdsetyy.smarthospital.hm","moduleName":"entry","id":0},"appDistributionType":"none","appProvisionType":"debug","systemApp":false,"dataUnclearable":false,"nativeLibraryPath":"/data/storage/el1/bundle/libs/arm64","appIndex":0,"multiAppMode":{"multiAppModeType":0,"maxCount":0},"installSource":"unknown","releaseType":"Release","cloudFileSyncEnabled":false,"flags":1},"currentHapModuleInfo":{"name":"entry","icon":"$media:bdsetyylogo_2","iconId":16777226,"label":"$string:EntryAbility_label","labelId":16777228,"description":"$string:module_desc","descriptionId":16777232,"mainElementName":"EntryAbility","abilitiesInfo":[{"bundleName":"com.bdsetyy.smarthospital.hm","moduleName":"entry","name":"EntryAbility","label":"$string:EntryAbility_label","labelId":16777228,"description":"$string:EntryAbility_desc","descriptionId":16777227,"icon":"$media:bdsetyylogo_2","iconId":16777226,"process":"","isVisible":true,"exported":true,"type":1,"orientation":0,"launchType":0,"permissions":[],"readPermission":"","writePermission":"","uri":"","deviceTypes":["phone","tablet","2in1"],"applicationInfo":{"name":"com.bdsetyy.smarthospital.hm","bundleType":0,"debug":true,"description":"","descriptionId":0,"enabled":true,"label":"$string:app_name","labelId":16777228,"icon":"$media:bdsetyylogo_2","iconId":16777226,"process":"com.bdsetyy.smarthospital.hm","permissions":["ohos.permission.APPROXIMATELY_LOCATION","ohos.permission.CAMERA","ohos.permission.GET_NETWORK_INFO","ohos.permission.INTERNET","ohos.permission.LOCATION","ohos.permission.LOCATION_IN_BACKGROUND","ohos.permission.MICROPHONE","ohos.permission.PRIVACY_WINDOW","ohos.permission.WRITE_MEDIA"],"entryDir":"","codePath":"/data/app/el1/bundle/public/com.bdsetyy.smarthospital.hm","metadata":{},"metadataArray":[],"removable":true,"accessTokenId":537423034,"uid":20020196,"iconResource":{"bundleName":"com.bdsetyy.smarthospital.hm","moduleName":"entry","id":16
最新发布
10-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值