我们试图从我们的网络服务生成 json。我们的 JSON 格式如下所示。我们正在使用球衣生成 JSON。
[
{
"InfoList": {
"name": "test",
"slot": "2",
},
"Info": {
"Id": "212",
"name": "sdsdsd",
},
"abcInfoList": [
{
"aname": "",
"slt": "1",
},
{
{
"aname": "",
"slt": "1",
}
],
},
{
"InfoList": {
"name": "test",
"slot": "2",
},
"Info": {
"Id": "212",
"name": "sdsdsd",
},
"abcInfoList": [
{
"aname": "",
"slt": "1",
},
{
{
"aname": "",
"slt": "1",
}
],
},
{
"InfoList": {
"name": "test",
"slot": "2",
},
"Info": {
"Id": "212",
"name": "sdsdsd",
},
"abcInfoList": [
{
"aname": "",
"slt": "1",
},
{
{
"aname": "",
"slt": "1",
}
],
},
]
我们在下面设计了一个类来保存生成 JSON 的值
@XmlRootElement(name="JasonClass")
public class JsonClass {
@XmlElement(name="InfoList")
public Info getInfoList()
{
return this.info;
}
public void setInfoList(InfoList infoList)
{
this.infoList=infoList;
}
@XmlElement(name="Info")
public Info getInfo()
{
return this.hostInformation;
}
public void setInfo(Info info)
{
this.info=info;
}
@XmlElement(name="abcInfoList")
public Info getabcInfoList()
{
return this.abcInfoList;
}
public void setabcInfoList(AbcInfoList abcInfoList)
{
this.abcInfoListt=abcInfoList;
}
}
And we are returning array of JsonClass for JSON.
@GET
@Path("/service")
@Produces("application/json")
public JsonClass[] getJsonList() {
JsonClass[] jsonList = new JsonClass[count];
//code for fliing array
//code for fliing array
return jsonList;
}
它正在生成,如下所示
{
"JasonClass":[
{
"InfoList": {
"name": "test",
"slot": "2",
},
"Info": {
"Id": "212",
"name": "sdsdsd",
},
"abcInfoList": [
{
"aname": "",
"slt": "1",
},
{
{
"aname": "",
"slt": "1",
}
],
},
{
"InfoList": {
"name": "test",
"slot": "2",
},
"Info": {
"Id": "212",
"name": "sdsdsd",
},
"abcInfoList": [
{
"aname": "",
"slt": "1",
},
{
{
"aname": "",
"slt": "1",
}
],
},
{
"InfoList": {
"name": "test",
"slot": "2",
},
"Info": {
"Id": "212",
"name": "sdsdsd",
},
"abcInfoList": [
{
"aname": "",
"slt": "1",
},
{
{
"aname": "",
"slt": "1",
}
],
},
]
}
但我们不希望 JSON 中有以下内容。我们只需要数组[]。如上所述(int he first json)。
{
"JasonClass":
}