[語法] JSON的語法結構問題
各位先進好,想要請問一下我結構哪邊有寫錯,一直抓不出來,謝謝
本段是從網站上擷取下來的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
待得到答案之後
我會再轉貼到本篇
留給後輩參考
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.231.131.51
※ 文章網址: https://www.ptt.cc/bbs/java/M.1503936724.A.95B.html
→
08/29 01:27, , 1F
08/29 01:27, 1F
→
08/29 07:20, , 2F
08/29 07:20, 2F
→
08/29 07:24, , 3F
08/29 07:24, 3F
→
08/29 07:41, , 4F
08/29 07:41, 4F
→
08/29 07:42, , 5F
08/29 07:42, 5F
→
08/29 07:42, , 6F
08/29 07:42, 6F
推
08/29 14:53, , 7F
08/29 14:53, 7F
java 近期熱門文章
PTT數位生活區 即時熱門文章