java - 如何通过改造从 json 数组中获取嵌套对象
问题描述
我看到很多关于此的帖子,但似乎都没有工作,因为它从未指定我应该如何实际获取 enque 方法中的数据。
这是我的主要片段:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://apidojo-yahoo-finance-v1.p.rapidapi.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();
这是我的 pojo 课:
@SerializedName("longName")
@Expose
private String longName;
@SerializedName("symbol")
@Expose
private String symbol;
@Expose
@SerializedName("regularMarketPrice")
private int regularMarketPrice;
public String getLongName() {
return longName;
}
public String getSymbol() {
return symbol;
}
public int getRegularMarketPrice() {
return regularMarketPrice;
}
这是界面:
@GET("market/get-quotes?region=US&lang=en&symbols=MSFT")
Call<StockItem> getStocks(
@Header("x-rapidapi-host") String host,
@Header("x-rapidapi-key") String key
);
最后是来自网站的 Json 响应:
{1 item
"quoteResponse":{2 items
"result":[1 item
0:{...}97 items
]
"error":NULL
} }
0里面只是我想得到的股票名称符号和价格
我真的需要为我必须经历的每个 json 数组对象创建新的 java 类作为对象吗?
解决方案
推荐阅读
- uart - 我在哪里从 UART 读取数据?
- angular - 使用选定的值设置隐藏的表单字段值
- pandas - 在熊猫数据框中按日期和计数值分组
- ios - AVPlayer 视频冻结但音频正在播放
- apache-spark - 将分隔符作为参数传递给 Spark
- c# - 排除某些特定控制器使用 Swashbuckle (OpenApiParameter) 添加的默认标头参数
- python - 组合字符串和整数来创建日期字符串会导致 TypeError
- linq - 如何在 Linq Query 中获取所有具有最高订单号的记录
- react-admin - 为什么编辑按钮没有调用我的自定义 dataProvider?
- arrays - 应用程序打开画廊而不是相机 - XCode,SwiftUI