[语法] JSON的语法结构问题

楼主: qpowjohn (pose)   2017-08-29 00:11:58
各位先进好,想要请问一下我结构哪边有写错,一直抓不出来,谢谢
本段是从网站上撷取下来的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
待得到答案之后
我会再转贴到本篇
留给后辈参考
谢谢
作者: nodoors (门都没有)   2017-08-29 01:27:00
Response[]?
楼主: qpowjohn (pose)   2017-08-29 07:20:00
response是JSON内的变量我设定大写是让我自己比较好辨识Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/FieldNamingStrategy早上才想起来,忘记附上错误代码
作者: swpoker (swpoker)   2017-08-29 14:53:00
你都把答案写出来了

Links booklink

Contact Us: admin [ a t ] ucptt.com