如何获取这种JSON?

时间:2016-03-03 10:34:06

标签: android json

我的JSON

它有视频,pdf,笔记。我想分别显示不同类型的资源。

任何帮助都会很棒。 我没有使用任何库

          {  
 "results":[  
  {  
     "id":136,
     "resType":"Videos",
     "resLink":"DwRTefPNYOQ",
     "resName":"Video",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  },
  {  
     "id":180,
     "resType":"Reference Videos",
     "resLink":"RCzulW_kGMk",
     "resName":"Vedic Age in India & Contribution to Culture by Mocomi Kids",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  },

此处重复视频

  {  
     "id":181,
     "resType":"Reference Videos",
     "resLink":"4l5VRDau4f8",
     "resName":"Ancient India's Contributions to the World by Ancient Discoveries",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  },
  {  
     "id":557,
     "resType":"Mind Maps",
     "resLink":"upload/33/mind map 2 .pdf",
     "resName":"MIND MAP 2",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  },
  {  
     "id":558,
     "resType":"Fill in the blanks",
     "resLink":"454",
     "resName":"Fill in the blanks",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  },
  {  
     "id":559,
     "resType":"True or False",
     "resLink":"455",
     "resName":"True or False",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  },
  {  
     "id":561,
     "resType":"Multiple Choice Questions",
     "resLink":"457",
     "resName":"Multiple Choice Questions ",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  },
  {  
     "id":567,
     "resType":"Mind Maps",
     "resLink":"upload/33/mindmap 1.pdf",
     "resName":"MIND MAP 1",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  }


],
   "status":"OK"
}

SecondActivity.java

     //some code
           new DownloadJSON().execute();}
     private class DownloadJSON extends AsyncTask<Void, Void, Void> {
    @Override
    protected Void doInBackground(Void... params) {

        world = new ArrayList<Details>();

        jsonobject = JSONfunctions
                .getJSONfromURL(url);

        try {
            // Locate the NodeList name
            jsonarray = jsonobject.getJSONArray("results");
            for (int i = 0; i < jsonarray.length(); i++) {
                jsonobject = jsonarray.getJSONObject(i);

                Details results = new Details();

                results.setResType(jsonobject.optString("Videos"));
                results.setResName(jsonobject.optString("Videos"));
                results.setResLink(jsonobject.optString("subject"));
               // results.setTopic(jsonobject.optString("topic"));
                results.setId(jsonobject.getInt("id"));
                //results.setFlag(jsonobject.optString("flag"));
               // world.add(results);


            }
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return null;
    }    }
}                                           

1 个答案:

答案 0 :(得分:0)

我不明白你是否想要使用外部库 但如果你这样做...
有两个非常好的:
1. org.json - Google支持的库,易于使用,功能强大。 org.json
2. Moshi - 真正酷的图书馆,真实的新功能和一些不错的功能。易于物体处理。 - Moshi

祝你好运我的朋友。