当前位置:网站首页>Fastjson determines whether the JSON string is object or list < object >
Fastjson determines whether the JSON string is object or list < object >
2022-04-22 05:40:00 【Siege lion with dream】
introduction
In daily development, it is often necessary to JSON String processing , The most important thing to deal with is JSON And objects , Because for collection objects and ordinary objects ,JSON The method of converting objects is different , We need to choose different methods for corresponding conversion according to different situations , The following code is the processing method when I am not sure whether the string to be processed is a collection object or an ordinary object , I hope I can give you some reference , throw away a brick in order to get a gem
Code
{
Object object = JSON.parse(jsonStr);
if ( object instanceof JSONObject) {
Object jsonObject = JSONObject.parse(jsonStr);
} else if ( object instanceof JSONArray) {
JSONArray jsonArray = JSONObject.parseArray(jsonStr);
} else {
system.out.println(" Type unknown ");
}
}
版权声明
本文为[Siege lion with dream]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220532240427.html
边栏推荐
猜你喜欢
随机推荐
判断链表是否有环
MySQL事务
I/O基础知识入门
JVM探究
list stream: reduce的使用实例
Do you know the implementation of strcpy?
力扣237. 删除链表指定节点
MySQL存储时间的最佳实践
Write a program to automatically generate the two-color ball number of welfare lottery with MATLAB
力扣19. 删除链表的倒数第 N 个结点
IDEA的安裝与使用技巧
kibana 搜索语法
动态创建数组(c6385 正在从“a”读取无效数据)
Simulate the infectious disease model with MATLAB (only do matlab simulation learning and practice, not actual situation and application)
供应链服务术语
strlen的三种实现方法你知道吗?
10.Advance Next Round
稳定性建设最佳实践
线程池的几个常识
MySQL index







