我对android很陌生,而且还在学习android。我正在使用Okhttp库进行程序中的httpcalls。我为简单的Get请求制作了rest。
api/FeaturedCourse (URL)
这是我的回应
[
{
"$id": "1",
"ExamId": 44,
"ImageName": "637064732146027131.jpg",
"ExamName": "Some Exam Name",
"Description": "Some Long Description Goes Here.",
"SellPriceUSD": 10,
"SellPriceINR": 490
}
]在这里之前我已经做好了。
@Override
public void onResponse(Call call, Response response) throws IOException {
String data = response.body().string();
nsjdemo.this.runOnUiThread(new Runnable() {
@Override
public void run() {
txtString.setText(data);
}
});
}这是在TextBox中显示API响应。但我想把Api的反应和列表联系起来。所以稍后我可以将它绑定到回收视图或列表视图。
发布于 2019-12-22 13:41:50
在搜索了很多之后,我找到了答案,没有更改服务器代码。
String jsonOutput = response;
Type listType = new TypeToken<List<DemoClass>>(){}.getType();
List<DemoClass> posts = gson.fromJson(jsonOutput, listType);https://stackoverflow.com/questions/59444519
复制相似问题