无法获取 JSON 对象的元素
我有一个包含一些json对象的jsonobject
"paths": {
"/api/{version}/RAW/getrawdata": {
"get": {
"tags": [
"RAw"
],
"summary": "/getrawdata",
"parameters": [
{
"name": "token",
"in": "header",
"description": "gettoken",
"schema": {
"type": "string"
},
"/api/{version}/filtered/getfinaldatadata": {
"get": {
"tags": [
"filtered"
],
"summary": "/getfinaldatadata",
Now I want to get the elements summary and tags and want to return the values. Its easy to get the value of summary but tags has [] so I don't know how to take the value e.g RAW .
I was trying something like this
package beans;
import org.apache.camel.Exchange;
import org.apache.camel.Header;
public class URIpattern {
@SuppressWarnings("deprecation")
public String URI(JSONObject json,
@Header (Exchange.SLIP_ENDPOINT) String previous) {
if(previous!=null){
return null;
JSONObject paths= json.getJSONObject("paths");
JSONObject summary = operation.getString("summary");
JSONObject tags = operation.getJSONObject("tags");
return tags + summary;
但这没有做任何事情。有人可以指导我,因为我是Java的新手。 任何帮助将不胜感激。提前致谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我猜你正在使用这个 Object 并且在定义的类中您有函数 getJSONArray 之后只需使用新的 ArrayObject 并从中提取您需要的数据。
Well I guess you are using this Object and inside the defined class you have the function getJSONArray after that just use the new ArrayObject and pull the data what you need out of it.
在 JSON 中,[] 中的值被视为数组。因此,如果您需要提取
tags
,则需要将它们放入一个数组中,例如,PS 我找不到有问题的 json 是有效的,因此我使用了一些 exmaple 来解释JSONArray。
In JSON values are present in [] are treated as arrays. So if you need to extract the
tags
, you will need to get them in a array like,P.S. I could not find the json posted in question to be valid, hence I have used some exmaple to explain the JSONArray.