java中获取json的所有key方法
作者:anguea 时间:2023-10-15 06:15:26
工作笔记(在不知道json的key时如何获取当前json的keys)
String json="{'name':'angui','age':'23','like':'吃水果'}";
JSONObject j = JSON.parseObject(json);
j.remove("age");
System.out.println(json.toString());
System.out.println(j.toJSONString());
//将json转换为key=value&key=value&...的形式
StringBuilder sb = new StringBuilder();
String sbString="";
try {
org.json.JSONObject jsonObject = new org.json.JSONObject(json);
Iterator iterator = jsonObject.keys();
while(iterator.hasNext()){
String key = (String) iterator.next();
sb.append("&"+key);
sb.append("="+jsonObject.getString(key));
}
sb.append("&key");
sbString = sb.substring(1);
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println(sbString);
来源:https://blog.csdn.net/anguea/article/details/66968335
标签:java,json,key
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#中怎样从指定字符串中查找并替换字符串?
2023-09-30 14:26:24
![](https://img.aspxhome.com/file/2023/6/83236_0s.jpg)
C#使用log4net记录日志
2022-12-04 03:08:35
![](https://img.aspxhome.com/file/2023/8/106448_0s.jpg)
Java代码为例讲解堆的性质和基本操作以及排序方法
2021-08-27 05:32:25
![](https://img.aspxhome.com/file/2023/5/76525_0s.jpg)
c++代码调试方式的几点建议
2023-07-05 05:31:35
android实现倒计时动态圈
2023-09-15 03:18:33
![](https://img.aspxhome.com/file/2023/7/138447_0s.jpg)
在Android中调用WebService实例
2023-10-27 12:00:10
![](https://img.aspxhome.com/file/2023/2/139082_0s.jpg)
C#基于时间轮调度实现延迟任务详解
2023-07-06 08:00:49
spring mvc+localResizeIMG实现HTML5端图片压缩上传
2023-07-11 15:31:51
Flutter Drawer抽屉菜单示例详解
2022-07-30 12:34:11
![](https://img.aspxhome.com/file/2023/8/138558_0s.jpg)
java.util.concurrent.ExecutionException 问题解决方法
2022-12-09 21:15:04
java.sql.Date和java.util.Date的区别详解
2023-11-28 16:15:09
SpringBoot ApplicationContext接口深入分析
2021-10-21 23:00:03
![](https://img.aspxhome.com/file/2023/6/61056_0s.png)
ViewFlipper实现上下翻滚轮播效果
2023-10-06 08:55:40
Maven中央仓库发布的实现方法
2023-12-09 07:15:06
![](https://img.aspxhome.com/file/2023/1/64521_0s.jpg)
Android 全屏无标题栏的三种实现方法
2022-01-05 03:01:31
基于SpringBoot多线程@Async的使用体验
2021-07-15 04:47:04
Mybatis与Jpa的区别和性能对比总结
2022-09-17 16:08:45
浅谈让@Value更方便的Spring自定义转换类
2023-10-06 14:01:02
![](https://img.aspxhome.com/file/2023/4/74754_0s.jpg)
Android ListView 条目多样式展示实例详解
2022-10-22 06:18:41
浅谈JVM垃圾回收有哪些常用算法
2022-02-28 16:51:56