android - how to change json import file from resource to http url -
hi, code load json form resource want change code load json url do? how change code me please. want load json form url me please
private jsonobject getcontent() throws ioexception, jsonexception { bufferedreader bufferedreader = null; try { inputstream instream = getresources().openrawresource(r.raw.json); bufferedinputstream bufferedstream = new bufferedinputstream(instream); inputstreamreader reader = new inputstreamreader(bufferedstream); bufferedreader = new bufferedreader(reader); stringbuilder builder = new stringbuilder(); string line = bufferedreader.readline(); while (line != null) { builder.append(line); line = bufferedreader.readline(); } return new jsonobject(builder.tostring()); } { if (bufferedreader != null) { bufferedreader.close(); } } } /** * populates table in main view data. * * @param data * read json data * @throws jsonexception */ private void populatetable(jsonobject data) throws jsonexception { jsonarray dataarray = data.getjsonobject("observations").getjsonarray("data"); final tablelayout table = (tablelayout) findviewbyid(r.id.table); (int = 0; < dataarray.length(); i++) { final view row = createrow(dataarray.getjsonobject(i)); table.post(new runnable() { public void run() { table.addview(row); } }); } } /** * creates row table based on observation. * * @param item * json object containing observation * @return created row * @throws jsonexception */ private view createrow(jsonobject item) throws jsonexception { view row = getlayoutinflater().inflate(r.layout.rows, null); ((textview) row.findviewbyid(r.id.localtime)).settext(item.getstring("local_date_time_full")); ((textview) row.findviewbyid(r.id.apprenttemp)).settext(item.getstring("apparent_t")); return row; }
your code not clear , not getting idea, may follow android json parsing tutorial helpful you.
Comments
Post a Comment