手动解析及数据链接地址

来源:互联网 发布:免费淘宝代码 编辑:程序博客网 时间:2024/06/05 20:35

public void initData() {        super.initData();        //把按钮显示出来        ib_menu.setVisibility(View.VISIBLE);        //设置标题        tv_base_title.setText("新闻");        //设置主页的内容        System.out.println("新闻中心的数据被初始化了...");        TextView textView = new TextView(mActivity);        textView.setText("新闻中心的内容。。。");        textView.setTextSize(30);        textView.setGravity(Gravity.CENTER);        textView.setTextColor(Color.RED);        //把当前TextView添加到FrameLayout        fl_base_content.addView(textView);        //联网请求数据(手动解析)        getDataFromNet();    }

private void getDataFromNet() { RequestParams params = new RequestParams("http://api.bilibili.com/online_list?_device=android&platform=android&typeid=13&sign=a520d8d8f7a7240013006e466c8044f7"); x.http().get(params, new Callback.CommonCallback<String>() { @Override public void onSuccess(String result) { TestDemo testDemo = parsedJson2(result); Log.e(TAG,"手动解析数据请求成功=="+result); Log.e(TAG, "手动解析成功==" + testDemo.getList().get(1).getTitle()); } @Override public void onError(Throwable ex, boolean isOnCallback) { Log.e(TAG,"手动解析-onError=="+isOnCallback); } @Override public void onCancelled(CancelledException cex) { Log.e(TAG,"手动解析-onCancelled=="); } @Override public void onFinished() { Log.e(TAG,"手动解析-onFinished=="); } });}private TestDemo parsedJson2(String json) { TestDemo testDemo = new TestDemo(); try { JSONObject jsonObject = new JSONObject(json); int code = jsonObject.optInt("code"); testDemo.setCode(code); JSONObject listObject = jsonObject.optJSONObject("list"); if(listObject != null){ List<TestDemo.ListEntity> list = new ArrayList<>(); testDemo.setList(list);//list数据加入到Bean对象中 for(int i=0;i<12;i++){ JSONObject dataobject = listObject.optJSONObject("" + i); if(dataobject != null){ TestDemo.ListEntity listEntity = new TestDemo.ListEntity(); String aid = dataobject.optString("aid"); listEntity.setAid(aid); String author = dataobject.optString("author"); listEntity.setAuthor(author); String create = dataobject.optString("create"); listEntity.setCreate(create); String description = dataobject.optString("description"); listEntity.setDescription(description); String duration = dataobject.optString("duration"); listEntity.setDuration(duration); String pic = dataobject.optString("pic"); listEntity.setPic(pic); String title = dataobject.optString("title"); listEntity.setTitle(title); String typename = dataobject.optString("typename"); listEntity.setTypename(typename); int mid = dataobject.optInt("mid"); listEntity.setMid(mid); //添加到集合中 list.add(listEntity); } } } } catch (JSONException e) { e.printStackTrace(); } return testDemo;}


手动解析数据:http://api.bilibili.com/online_list?_device=android&platform=android&typeid=13&sign=a520d8d8f7a7240013006e466c8044f7。

key:为数字时,必须手动解析。


JSON
  • code0
  • list
    • 0
      • aid"6892379"
      • typeid33
      • title"【7月】齐木楠雄的灾难(日播版) 86"
      • pic"http://i1.hdslb.com/bfs/archive/72863c4a58446c1b793c6b97746e2fb6e0aa82c0.jpg"
      • play"358603"
      • video_review"3113"
      • author"TV-TOKYO"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review18
      • favorites148
      • mid21453565
      • description"#86 照桥的齐木家之行"
      • create"2016-10-30 18:45"
      • credit0
      • coins1719
      • duration"4:19"
      • online3071
    • 1
      • aid"6892370"
      • typeid33
      • title"【7月】齐木楠雄的灾难 17"
      • pic"http://i1.hdslb.com/bfs/archive/98bfe0046f68c315d183541ce1809563f7e93a96.jpg"
      • play"124874"
      • video_review"2605"
      • author"TV-TOKYO"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review1
      • favorites100
      • mid21453565
      • description"#17 "
      • create"2016-10-30 18:45"
      • credit0
      • coins764
      • duration"23:54"
      • online2865
    • 2
      • aid"6892377"
      • typeid33
      • title"【10月】刀剑乱舞 -花丸- 05"
      • pic"http://i0.hdslb.com/bfs/archive/bd192914ba4c6ff0a8ee35590d6a72e348b12f44.jpg"
      • play"83931"
      • video_review"11065"
      • author"哔哩哔哩番剧"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review19
      • favorites461
      • mid928123
      • description"#05 "
      • create"2016-10-30 18:45"
      • credit0
      • coins976
      • duration"24:00"
      • online1754
    • 3
      • aid"6869583"
      • typeid33
      • title"【10月】亚人 第二季 04【幻樱】"
      • pic"http://i2.hdslb.com/bfs/archive/028126a8219962f8864ec4ba0feac57987a86b7f.jpg"
      • play"505236"
      • video_review"13211"
      • author"真鱼"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review10
      • favorites585
      • mid81192
      • description" 基友登场"
      • create"2016-10-29 13:22"
      • credit0
      • coins3404
      • duration"24:27"
      • online1164
    • 4
      • aid"6873386"
      • typeid33
      • title"【10月】超自然9人组 04"
      • pic"http://i0.hdslb.com/bfs/archive/d7f62d7c1a1018057b1b973771b8bb34a4d5119c.jpg"
      • play"169548"
      • video_review"3783"
      • author"哔哩哔哩番剧"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review16
      • favorites181
      • mid928123
      • description"#04 犯人是我闻悠太"
      • create"2016-10-29 17:18"
      • credit0
      • coins1308
      • duration"24:04"
      • online696
    • 5
      • aid"6880023"
      • typeid33
      • title"【10月】乌冬面之国的金色毛球 04"
      • pic"http://i1.hdslb.com/bfs/archive/fd793ec54defff81c77aa556bf1e6951cb416139.jpg"
      • play"142182"
      • video_review"4349"
      • author"哔哩哔哩番剧"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review5
      • favorites210
      • mid928123
      • description"#04 屋岛"
      • create"2016-10-29 23:31"
      • credit0
      • coins957
      • duration"23:00"
      • online484
    • 6
      • aid"6827549"
      • typeid33
      • title"【10月】夏目友人帐 第五季 04"
      • pic"http://i2.hdslb.com/bfs/archive/fdf20add104763dc234af8eb6c98d9a5f7588205.jpg"
      • play"996760"
      • video_review"41056"
      • author"哔哩哔哩番剧"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review31
      • favorites1154
      • mid928123
      • description"#04 连锁的背后"
      • create"2016-10-26 00:00"
      • credit0
      • coins9547
      • duration"23:51"
      • online482
    • 7
      • aid"6873384"
      • typeid33
      • title"【10月】WWW.迷糊餐厅 05"
      • pic"http://i0.hdslb.com/bfs/archive/bcf851af725ee38e4bd2c8ea735c26f0fd4e5a8f.jpg"
      • play"188572"
      • video_review"4505"
      • author"哔哩哔哩番剧"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review4
      • favorites99
      • mid928123
      • description"#05 我要报仇"
      • create"2016-10-29 17:18"
      • credit0
      • coins1268
      • duration"23:51"
      • online434
    • 8
      • aid"6904405"
      • typeid33
      • title"【10月】12岁 17【独家正版】"
      • pic"http://i0.hdslb.com/bfs/archive/6b242c54e5be7c2b4964ccb1f34409cd8dafbb09.jpg"
      • play"2873"
      • video_review"564"
      • author"哔哩哔哩番剧"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review2
      • favorites10
      • mid928123
      • description"#17 「雨过天晴」"
      • create"2016-10-31 17:04"
      • credit0
      • coins13
      • duration"23:51"
      • online427
    • 9
      • aid"6880026"
      • typeid33
      • title"【10月】三月的狮子 04"
      • pic"http://i0.hdslb.com/bfs/archive/1eb72d303207271299e23e2d4ca67fc174c65499.jpg"
      • play"107674"
      • video_review"4318"
      • author"哔哩哔哩番剧"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review5
      • favorites138
      • mid928123
      • description"#04 日向 / VS"
      • create"2016-10-29 23:31"
      • credit0
      • coins1197
      • duration"25:05"
      • online394
    • 10
      • aid"6899338"
      • typeid33
      • title"【10月】月曜日的tawawa 04【幻樱】"
      • pic"http://i0.hdslb.com/bfs/archive/42f997e4b2b958647389f665709779cc2bfe5a77.jpg"
      • play"40419"
      • video_review"701"
      • author"残星什么的就是残星"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review8
      • favorites170
      • mid58426
      • description" 帮真鱼代投一话w"
      • create"2016-10-31 08:40"
      • credit0
      • coins635
      • duration"4:55"
      • online363
    • 11
      • aid"6892362"
      • typeid33
      • title"【10月】SHOW BY ROCK!! 第二季 05【独家正版】"
      • pic"http://i0.hdslb.com/bfs/archive/cb4a6f068c0e6ee472c6266cbee415e27e82917f.jpg"
      • play"18437"
      • video_review"1205"
      • author"哔哩哔哩番剧"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review5
      • favorites50
      • mid928123
      • description"#05 Just awake"
      • create"2016-10-30 18:45"
      • credit0
      • coins148
      • duration"23:40"
      • online312
    • 12
      • aid"6853737"
      • typeid33
      • title"【10月】我太受欢迎了该怎么办 04"
      • pic"http://i0.hdslb.com/bfs/archive/d2253736ae01be6bcb7dd832a12c4a02b34011a1.jpg"
      • play"560829"
      • video_review"55301"
      • author"哔哩哔哩番剧"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review42
      • favorites806
      • mid928123
      • description"#04 圣诞节要在圣地度过 "
      • create"2016-10-28 11:29"
      • credit0
      • coins3252
      • duration"24:10"
      • online283
    • 13
      • aid"6877310"
      • typeid33
      • title"【10月】终末的伊泽塔 05"
      • pic"http://i0.hdslb.com/bfs/archive/b7e8ba4f8600812e9d2be0f2732ada0f666934d6.jpg"
      • play"116819"
      • video_review"6575"
      • author"哔哩哔哩番剧"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review7
      • favorites106
      • mid928123
      • description"#05 虚假的奇迹"
      • create"2016-10-29 21:02"
      • credit0
      • coins1008
      • duration"25:16"
      • online242
    • 14
      • aid"6880714"
      • typeid33
      • title"【10月】魔法少女育成计划 05【独家正版】"
      • pic"http://i1.hdslb.com/bfs/archive/e3fcabacab9eeb1bdeba8849aa378b16aa8704a1.jpg"
      • play"121127"
      • video_review"6773"
      • author"哔哩哔哩番剧"
      • copyright"Copy"
      • typename"连载动画"
      • subtitle""
      • review31
      • favorites106
      • mid928123
      • description"#05 追加新角色"
      • create"2016-10-30 00:16"
      • credit0
      • coins842
      • duration"24:00"
      • online230

0 0
原创粉丝点击