java - 如何在java中解码这个json对象数据
问题描述
我得到了这个 json 对象数据,它是
{
"data": {
"id": 2,
"email": "janet.weaver@reqres.in",
"first_name": "Janet",
"last_name": "Weaver",
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg"
},
"ad": {
"company": "StatusCode Weekly",
"url": "http://statuscode.org/",
"text": "A weekly newsletter focusing on software development, infrastructure, the server, performance, and the stack end of things."
}
}
我想解析我想在对象中打印输出电子邮件的 json...我使用 org.simple.json 库。
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("curl -s -S https://reqres.in/api/users/2");
BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String result = br.readLine();
Object obj=JSONValue.parse(result);
如何通过数据打印电子邮件数据 -> 电子邮件
解决方案
您可以将值转换为JSONObject
并进一步使用JSONObject
API 进行打印
JSONObject jsonObject = (JSONObject) JSONValue.parse(result);
JSONObject data = (JSONObject) jsonObject.get("data");
String email= (String) data.get("email");
System.out.println("Email= " + email);
推荐阅读
- r - 如何在R中的函数内为函数提供动态数量的参数?
- webgl - 禁用混合时WebGL如何返回像素颜色?
- yahoo-finance - 为什么我在从 Yahoo 财务模块下载数据时收到 JSONDecodeError
- powershell-5.1 - Powershell - 从哈希表集合中获取不同的值
- reactjs - 无法在 Mac os 中使用 nvm 安装 nodejs 版本
- node.js - 如何在 POST 请求中发送 GET 请求的结果?
- scala - spark scala 条件连接替换空值
- forms - 当目标页面被重定向到另一个页面时,有没有办法通过表单传递数据?
- c# - Android 上的 Xamarin Profiler 错误(运行时太旧)
- jsf - 如何在执行ajax更新时将参数从primefaces传递给java bean