当前位置:网站首页>JSON字符串转化为JSON对象,获取某个key的值,判断某个key是否存在
JSON字符串转化为JSON对象,获取某个key的值,判断某个key是否存在
2022-07-26 21:29:00 【abs(ln(1+NaN))】
前端vue给后端传递一个对象类型的数据时,前端先将对象转化为json字符串,然后再传递给后端,此时后端就需要解析这个json字字符串,并取出对应的属性值。
1、JSON字符串转化为JSON对象
import com.alibaba.fastjson.JSONObject;
String jsonStr = "{\"id\": 2," +
" \"title\": \"json title\", " +
"\"config\": {" +
"\"width\": 34," +
"\"height\": 35," +
"}, \"data\": [" +
"\"JAVA\", \"JavaScript\", \"PHP\"" +
"]}";
//将json字符串转化为json对象
JSONObject jsonobj = JSONObject.parseObject(jsonStr);![]()
2、取出某一属性的值
//这里的id是json对象的键名
String value = jsonobj.getString("data");
3、判断某个key是否存在
import com.alibaba.fastjson.JSONObject;
jsonobj.containsKey("message"); //如果存在key名为 "message" ,返回true;否则返回false边栏推荐
- day07-
- 09.01 深度优先搜索
- 同花顺手机炒股开户安全吗?怎么办理开户呢
- JDBC operation and entry case of MySQL
- JMeter自定义日志与日志分析
- View绘制流程1-View与Window的关系
- 08.02 adjacency table
- Is it safe to open an account on flush? How to choose a securities firm for opening an account
- Want the clouds in the picture to float? Video editing services can be achieved in three steps with one click
- SQL注入 Less26(过滤空格和注释符,使用不带空格的报错注入)
猜你喜欢
随机推荐
Li Kou daily question - day 43 -168. Name of Excel table column
ZABBIX calls API retrieval method
Oppo self-developed large-scale knowledge map and its application in digital intelligence engineering
07 DF command
实际权威来自信息优势
06 cp 命令
JS delay execution window.onload
In depth analysis of the source code, why is the string class immutable? (hit me before you understand)
07 df 命令
正规方程法(Normal Equation)原理以及与梯度下降法的区别
Xshell7 personal free download, use
matlab 画短时能量图
Is it safe to open an account for flush mobile stock trading? How to open an account
Flink's real-time data analysis practice in iFLYTEK AI marketing business
Redis 分布式锁 + Lua原子操作
Want the clouds in the picture to float? Video editing services can be achieved in three steps with one click
[tool] apifox
光源控制器拨码开关使用说明
知识库工具 | 微网站、文档中心、形象展示页拖拽即可生成(附模板,直接用)
JS 延迟执行window.onload
![[tool] apifox](/img/a8/73325ec02a8bed2db2a8168f5bd40e.png)








