这是我的json
{
"columns": [
"logoFileName",
"logoFileName1",
"companyEventIDUnique",
"Date",
"Event",
"soldOut",
"companyEventGroupDescription",
"eventImageFileName",
"teamsImagePath"
],
"rows": [
[
"RoyalChallengersBangalore11.png",
"SH11.png",
14,
"Monday, 13 Apr 2015, 8:00PM",
"Royal Challengers Bangalore Vs Sunrisers Hyderabad ",
0,
"RCB Home Games 2015",
"rcb-srh.png",
"images/upload/team/"
],
[
"RoyalChallengersBangalore11.png",
"MumbaiIndiansLogo.png",
15,
"Sunday, 19 Apr 2015, 8:00PM",
"Royal Challengers Bangalore Vs Mumbai Indians ",
0,
"RCB Home Games 2015",
"rcb-mi.png",
"images/upload/team/"
],
[
"RoyalChallengersBangalore11.png",
"ChennaiSuperKingsLogo11.png",
16,
"Wednesday, 22 Apr 2015, 8:00PM",
"Royal Challengers Bangalore Vs Chennai Super Kings ",
0,
"RCB Home Games 2015",
"rcb-csk.png",
"images/upload/team/"
],
[
"RoyalChallengersBangalore11.png",
"RajasthanRoyalsLogo11.png",
17,
"Wednesday, 29 Apr 2015, 8:00PM",
"Royal Challengers Bangalore Vs Rajasthan Royals ",
0,
"RCB Home Games 2015",
"rcb-rr.png",
"images/upload/team/"
],
[
"RoyalChallengersBangalore11.png",
"KKR_logo.png",
18,
"Saturday, 02 May 2015, 4:00PM",
"Royal Challengers Bangalore Vs Kolkata Knight Riders ",
0,
"RCB Home Games 2015",
"rcb-kkr.png",
"images/upload/team/"
],
[
"RoyalChallengersBangalore11.png",
"KingsXIPunjabLogo11.png",
19,
"Wednesday, 06 May 2015, 8:00PM",
"Royal Challengers Bangalore Vs Kings XI Punjab ",
0,
"RCB Home Games 2015",
"rcb-kxip.png",
"images/upload/team/"
],
[
"RoyalChallengersBangalore11.png",
"DelhiDaredevilsLogo12.png",
20,
"Sunday, 17 May 2015, 4:00PM",
"Royal Challengers Bangalore Vs Delhi DareDevils ",
0,
"RCB Home Games 2015",
"rcb-dd.png",
"images/upload/team/"
]
]
}
以下是我的POJO我无法解析上述数据
公共类EventHandler {
public String logoFileName;
public String logoFileName1;
public int companyEventIDUnique;
public String Date;
public String Event;
public int soldOut;
public String companyEventGroupDescription;
public String eventImageFileName;
public String teamsImagePath;
public EventHandler() {
}
public EventHandler(String logoFileName, String logoFileName1,
int companyEventIDUnique, String Date, String Event, int soldOut,
String companyEventGroupDescription, String eventImageFileName,
String teamsImagePath) {
this.logoFileName = logoFileName;
this.logoFileName1 = logoFileName1;
this.companyEventIDUnique = companyEventIDUnique;
this.companyEventGroupDescription = companyEventGroupDescription;
this.eventImageFileName = eventImageFileName;
this.teamsImagePath = teamsImagePath;
}
public String getLogoFileName() {
return logoFileName;
}
public void setLogoFileName(String logoFileName) {
this.logoFileName = logoFileName;
}
public String getLogoFileName1() {
return logoFileName1;
}
public void setLogoFileName1(String logoFileName1) {
this.logoFileName1 = logoFileName1;
}
public int getCompanyEventIDUnique() {
return companyEventIDUnique;
}
public void setCompanyEventIDUnique(int companyEventIDUnique) {
this.companyEventIDUnique = companyEventIDUnique;
}
public String getDate() {
return Date;
}
public void setDate(String date) {
Date = date;
}
public String getEvent() {
return Event;
}
public void setEvent(String event) {
Event = event;
}
public int getSoldOut() {
return soldOut;
}
public void setSoldOut(int soldOut) {
this.soldOut = soldOut;
}
public String getCompanyEventGroupDescription() {
return companyEventGroupDescription;
}
public void setCompanyEventGroupDescription(
String companyEventGroupDescription) {
this.companyEventGroupDescription = companyEventGroupDescription;
}
public String getEventImageFileName() {
return eventImageFileName;
}
public void setEventImageFileName(String eventImageFileName) {
this.eventImageFileName = eventImageFileName;
}
public String getTeamsImagePath() {
return teamsImagePath;
}
public void setTeamsImagePath(String teamsImagePath) {
this.teamsImagePath = teamsImagePath;
}
}
答案 0 :(得分:0)
你给的json字符串不是json.Json必须是Key-value pair.refer这个doc.Hope它会有所帮助。 Introducing JSON
它应该像
{
"key": [
{
"key": "value"
},
{
"key": "value"
}
]
}
答案 1 :(得分:0)
如果您在字符串中获取数据,那么您可以像这样解析它。
JsonObject obj = new JsonObject(urString)
jsonArray a1 = obj.getJsonArray("columns");
for(i=0; i<a1.length();i++){
// get all String here
}
jsonArray a2 = obj.getJsonArray("row");
for(i=0; i<a2.length();i++){
jsonArray a3 = a2.getJsonArray("i");
for(i=0; i<a3.length();i++){
//find all String here;
}
}
答案 2 :(得分:0)
JSONObject one = new JSONObject(json);
JSONArray columns = one.getJSONArray("columns");
for (int i = 0; i < columns.length(); i++)
{
String str = columns.getString(i);
System.out.println("Colums Strings : " + str);
}
JSONArray rows = one.getJSONArray("rows");
for (int i = 0; i < rows.length(); i++)
{
JSONArray array = rows.getJSONArray(i);
for (int j = 0; j < array.length(); j++)
{
String str1 = array.getString(j);
System.out.println("Rows Strings : " + str1);
}
}