如何获取 JSON 数据

How to fetch JSON Data

这是我需要从中获取数据的 JSON 文件:

{}JSON
     []Learning Standards
       {}0
        {}Learning Standards
          * standard_title : Sample_1
          * ref_id : TSB_01
          * description :  This is a sample JSON Format
        {}1
         {}Learning Standards
          * standard_title : Sample_2
          * ref_id : TSB_02
          * description :  This is a sample JSON Format
         {}2
          {}Learning Standards
          * standard_title : Sample_3
          * ref_id : TSB_03
          * description :  This is a sample JSON Format

          {}3
           {}4
             {}5
               {}6

我的代码如下,

// JSON file URL address 
jsonobject = JSONfunctions.getJSONfromURL("54.152.108.131/iphone111/getLearningStandards");
try {
    // Locate the NodeList name 
    jsonarray = jsonobject.getJSONArray("LearningStandards");
    for (int i = 0; i < jsonarray.length(); i++) {
        jsonobject = jsonarray.getJSONObject(i);
        WorldPopulation worldpop = new WorldPopulation();
        worldpop.setRank(jsonobject.optString("standard_title"));
        worldpop.setCountry(jsonobject.optString("ref_id"));
        worldpop.setPopulation(jsonobject.optString("description"));
    }
} catch(Exception e){
    e.printStackTrace();
}

试试这个,

// JSON file URL address 
jsonobject = JSONfunctions.getJSONfromURL("http://54.152.108.131/iphone111/getLearningStandards");
try {
    ArrayList<WorldPopulation> worldpopArray = new ArrayList<WorldPopulation>();
    ArrayList<String> spinnerArray = new ArrayList<String>();
    // Locate the NodeList name 
    jsonarray = jsonobject.getJSONArray("LearningStandards");
    for (int i = 0; i < jsonarray.length(); i++) {
        jsonobject = jsonarray.getJSONObject(i);
        jsonobject = jsonobject.getJSONObject("LearningStandards");
        WorldPopulation worldpop = new WorldPopulation();
        worldpop.setRank(jsonobject.optString("standard_title"));
        worldpop.setCountry(jsonobject.optString("ref_id"));
        worldpop.setPopulation(jsonobject.optString("description"));
        worldpopArray.add(worldpop);
        spinnerArray.add(jsonobject.optString("standard_title"));
    }

    //Bind spinnerArray to your Spinner

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