android - Get specific json object by ID using GSON -


i trying develop skills in json parsing. have found have implement kind of json parsing library example gson. have json example here. , code using values json:

private class postfetcher extends asynctask<void, void, string> {     private static final string tag = "postfetcher";     public static final string server_url = "http://kylewbanks.com/rest/posts";      @override     protected string doinbackground(void... params) {         try {             //create http client             httpclient client = new defaulthttpclient();             httppost post = new httppost(server_url);              //perform request , check status code             httpresponse response = client.execute(post);             statusline statusline = response.getstatusline();             if(statusline.getstatuscode() == 200) {                 httpentity entity = response.getentity();                 inputstream content = entity.getcontent();                  try {                     //read server response , attempt parse json                     reader reader = new inputstreamreader(content);                      gsonbuilder gsonbuilder = new gsonbuilder();                     gsonbuilder.setdateformat("m/d/yy hh:mm a");                     gson gson = gsonbuilder.create();                     list<post> posts = arrays.aslist(gson.fromjson(reader, post[].class));                     content.close();                      handlepostslist(posts);                 } catch (exception ex) {                     log.e(tag, "failed parse json due to: " + ex);                     failedloadingposts();                 }             } else {                 log.e(tag, "server responded status code: " + statusline.getstatuscode());                 failedloadingposts();             }         } catch(exception ex) {             log.e(tag, "failed send http post request due to: " + ex);             failedloadingposts();         }         return null;     }  } 

what trying find out whether possible data 1 json object using id. possible or not , if possible please me understand because in deadlock , cannot understand lot of things gson.

i have found maybe there similar in gson?:

for (int = 0; < recs.length(); ++i) {     jsonobject rec = recs.getjsonobject(i);     int id = rec.getint("id");     string loc = rec.getstring("loc");     // ... } 


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -