各位先進好,想要請問一下我結構哪邊有寫錯,一直抓不出來,謝謝
本段是從網站上擷取下來的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
待得到答案之後
我會再轉貼到本篇
留給後輩參考
謝謝