各位先进好,想要请问一下我结构哪边有写错,一直抓不出来,谢谢
本段是从网站上撷取下来的API,格式为JSON
{
"code":200,
"response":
{
"sell":
[
{
"online_status":false,
"price":5,
"count":2,
"online_ingame":false,
"ingame_name":"name"
}
]
"buy":
[
{
"online_status":false,
"price":1,
"count":5,
"online_ingame":false,
"ingame_name":"name"
}
]
"render_rank":false
}
}
为了节省版面buy和sell各撷取一段出来
以下是我写的内容
主程式呼叫的语法
Category category = new Gson().fromJson(url, Category.class);
url已经用Syetem.out.print确认过可以输出内容
以下是Category的内容,为节约版面,把Getter和Setter先拿掉
package Main;
import com.google.gson.annotations.SerializedName;
public class Category {
private int code;
private Response[] responses;
public Category() {
}
static class Response {
@SerializedName("sell")
private Sell[] sell;
@SerializedName("buy")
private Buy[] buy;
@SerializedName("render_rank")
private boolean render_rank;
public Response() {
}
static class Buy {
@SerializedName("online_status")
private boolean online_status;
@SerializedName("price")
private int price;
@SerializedName("count")
private int count;
@SerializedName("online_ingame")
private boolean online_ingame;
@SerializedName("ingame_name")
private String ingame_name;
public Buy() {
}
}
}
}
感谢各位先进花时间看完本篇问题
如果PTT不好撰写的话
请在以下网址填入程式码
https://goo.gl/g9R7hm
待得到答案之后
我会再转贴到本篇
留给后辈参考
谢谢