Android无法解析JSON数据

时间:2015-03-12 05:49:37

标签: android json

这是我的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/"
    ]
]
 }

我无法解析它。请帮助我如何解析它。

1 个答案:

答案 0 :(得分:-1)

你可以解析一些像下面的代码 -

try{
        String result = "YOUR JSON DATA";
        JSONObject json = new JSONObject(result);
        JSONArray jArrayColumns = json.getJSONArray("columns"); 
        for(int i=0;i<jArrayColumns.length();i++){
            String data = jArrayColumns.getString(i);
            Log.i("TAG", "JSON ARRAY"+data);
        }
        JSONArray jArrayRows = json.getJSONArray("rows"); 
        for(int i=0;i<jArrayRows.length();i++){
            JSONArray jRowItem = jArrayColumns.getJSONArray(i);
            for(int j=0;j<jRowItem.length();j++){
                String rowItem = jRowItem.getString(j);
            }
            Log.i("TAG", "JSON ARRAY rowItem"+rowItem);
        }


    }
    catch(Exception e){
        e.printStackTrace();
    }