How to parse a keyless json array on Android? -
this question has answer here:
- how parse json in android 4 answers
i have been trying parse keyless json array while. know there plenty of tutorials on how parse json arrays, follow same pattern. have website on here trying parse , display text. http://ec2-54-213-155-95.us-west-2.compute.amazonaws.com/notices.php
defaulthttpclient httpclient = new defaulthttpclient(new basichttpparams()); httppost httppost = new httppost("http://ec2-54-213-155-95.us-west-2.compute.amazonaws.com/notices.php"); // depends on web service httppost.setheader("content-type", "application/json"); inputstream inputstream = null; string result = null; try { httpresponse response = httpclient.execute(httppost); httpentity entity = response.getentity(); inputstream = entity.getcontent(); // json utf-8 default bufferedreader reader = new bufferedreader(new inputstreamreader(inputstream, "utf-8"), 8); stringbuilder sb = new stringbuilder(); string line = null; while ((line = reader.readline()) != null) { sb.append(line + "\n"); } result = sb.tostring(); } catch (exception e) { // oops } { try{if(inputstream != null)inputstream.close();}catch(exception squish){} } jsonobject jobject = new jsonobject(result); }
i stuck here. should here?
this should not diffcicult. see below code. syntax errors , handle exceptions, typed it.
jsonarray jsonarray = jobject.getjsonarray("notices"); for(int = 0; < jsonarray.length(); i++) { string string = jsonarray.getstring(i); log.d("tag", string); // whatever want "string" }
Comments
Post a Comment