0

私のAndroidアプリケーションでは、サーバーからのJson応答があります:

[
   {
    "sm": [
      {
        "tbico": "b43-jeep.png",
        "t": "Welcome!",
        "w": "http://google.com/start",
        "st": "w",
        "wTBL": "wTBLN"
      }, {
        "t": "Content screen title",
        "f": "Eltec%20Spec%20sheet%20Gim%20RD30W.pdf",
        "st": "f"
      }, {
        "tbico": "109-chicken.png",
        "t": "Sub menu",
        "sm": [
          {
            "t": "Screen 1",
            "st": "f"
          }, {
            "t": "Screen 2",
            "w": "Http://google.com",
            "st": "w",
            "wTBL": "wTBLT"
          }
        ],
        "st": "sm"
      }, {
        "st": "f"
      }
    ],
    "st": "tbm"
  }
]

今、Gson を使用して、この JSON ファイルを次のように解析しています。

//USING GSON In Parse.java
public class Parse {
    public class Setting {
        String sett;
        int[] clorBG;
        int[] colrTR;
        int[] colrTRT;
        int fntIcoGrd;
        boolean statBr;
        //List<Share> shrMnuPrest;   //Place name that matches to json from json-file element
        List<SM> sm;
        List<Share> shrMnuPrest;
        /*
        public boolean getStatbar(){
            return statBr;
        }
        public boolean setStatbar(){
            return this.statBr;
        }*/
    }
    public class Share {
        String shrFBLnk;
        String shrTwtBdy;
        String shrTxtMsgBdy;
        String shrFBBdy;
        String sndEmlBtn;
    }
    public class Screen {
        String tbico;
        String t;
        String st;
        List<SM> sm;
        //List<SM2> sm2; should auto load from <SM> List
    }
    public class SM { //for Table View
        String bgFile;
        String icoSz;
        String t;
        boolean gvHIT;
        int gvNR;
        int gvNC;
        String st;
        List<SM2> sm2;
        List<Share> share;
    }
    static class SM2 { //Sub-menu screen type
        String st;
        String t;
        String f;
        String cusico;
        String bgFile;
        String icoSz;
        String fb;
        String wTBL;
        String w;
    }
    public static void main(String[] args) throws Exception {
        Log.i("RUNNING", "Running Main call");
        String jsonLink = readUrl("http://10.0.2.2/" + "json/config.json");
        JsonElement json = new JsonParser().parse(jsonLink);
        JsonArray array = json.getAsJsonArray();
        Iterator iterator = array.iterator();
        while (iterator.hasNext()) {
            JsonElement json2 = (JsonElement) iterator.next();
            Gson gson = new Gson();
            Setting sett = gson.fromJson(json2, Setting.class);
            //prints entire class
            System.out.println(sett.toString());
            //print WHAT you want!!
            System.out.println(sett.statBr);
            System.out.println(sett.clorBG);
            //System.out.println(sett.colrTRT);
            System.out.println(sett.colrTRT);
        }
        //Gson gson = new Gson();
        //Setting sett = gson.fromJson(json, Setting.class);
        //System.out.println(sett.toString());
    }
}

関数を実行すると、gson で NullPointer としてエラーが発生します。私が欲しいのは、このJSONを解析して、アプリでこのファイルの値を使用できるようにすることだけです.同様にhttp://pastebin.com/TJMuG67b エラー : http://cl.ly/image/2q0Z0Q0m3F26

4

0 に答える 0