当前位置:网站首页>fastjson判断JSON字符串是Object还是List<Object>
fastjson判断JSON字符串是Object还是List<Object>
2022-04-22 05:32:00 【有梦想的攻城狮】
引言
日常开发中经常需要对JSON字符串进行处理,处理的最多的便是进行JSON和对象之间的转换,由于对于集合对象和普通对象,JSON转对象的方法是不同的,我们需要根据不同情况来选择不同的方法进行对应的转换,下面的这段代码就是我在开发中碰到的对于如果不确定要处理的字符串是一个集合对象还是普通对象的时候的处理方法,希望可以给大家一些借鉴,抛砖引玉
代码
{
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("类型未知");
}
}
版权声明
本文为[有梦想的攻城狮]所创,转载请带上原文链接,感谢
https://zhangzehai.blog.csdn.net/article/details/111570802
边栏推荐
- C language version: establishment of circular linked list
- Configure security policy on ENSP
- MySQL事务
- GBase 8s V8. 8 SQL Guide: tutorial-5.4
- 认识和安装MySQL
- Fundamentals of Unreal Engine Programming (II)
- MySQL 第7章 对数据表的复杂查询
- 【FedMD,一种利用模型蒸馏的异构FL训练方法】FedMD: Heterogenous Federated Learning via Model Distillation
- Realization of mathematical function curve editor with minscript script language
- 有限单元法基本原理和数值方法_有限元法基本原理
猜你喜欢

MySQL基础命令及练习题(一)

Fundamentals of graphics - Ambient Occlusion

MySQL 第6章 Navicat 的安装与使用

深圳-西双版纳

MySQL JDBC 编程

二叉树五个重要性质(附图理解)
My creation anniversary

C language version: static establishment of binary tree

Unable to resolve dependency for ': app@debug /compileClasspath': Could not download mapsforge-map. jar

Fundamentals of graphics - depth of field / DOF
随机推荐
GBase 8s V8.8 SQL 指南:教程-5.2(3)
C language practice (2) -- polynomial addition with linked list
Online Tetris with automatic hang-up source code
Installation and use of SQL map
Unity list uses find or findall to find specific elements and the number of specific elements
Fundamentals of graphics - screen spatial reflection (SSR)
Integer源码
Application and selection of it power distribution and fire current limiting protector
MySQL索引
C language version: establishment and basic operation of two-way linked list
Unity is limited to execute every few frames in update
2022.4.21-----leetcode. eight hundred and twenty-four
Shenzhen Xishuangbanna
MySQL 第6章 Navicat 的安装与使用
Cookie injection
Fundamentals of graphics - flood
GBase 8s V8.8 SQL 指南:教程-6.1
MySQL表约束和表设计
Four startup modes of activity
Integer source code