作者qpowjohn (pose)
看板java
标题[语法] JSON的语法结构问题
时间Tue Aug 29 00:11:58 2017
各位先进好,想要请问一下我结构哪边有写错,一直抓不出来,谢谢
本段是从网站上撷取下来的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://webptt.com/cn.aspx?n=bbs/java/M.1503936724.A.95B.html
1F:→ nodoors: Response[]? 08/29 01:27
2F:→ qpowjohn: response是JSON内的变数 08/29 07:20
3F:→ qpowjohn: 我设定大写是让我自己比较好辨识 08/29 07:24
4F:→ qpowjohn: Exception in thread "main" java.lang.NoClassDefFound 08/29 07:41
5F:→ qpowjohn: Error: com/google/gson/FieldNamingStrategy 08/29 07:42
6F:→ qpowjohn: 早上才想起来,忘记附上错误代码 08/29 07:42
7F:推 swpoker: 你都把答案写出来了 08/29 14:53