java - how to avoid a Json array when i'm fetching data -
i'm fetching json info in java, , json have different construction , not same. illustration :
{"0":{"id"="255",name="example"},"1":{"news_id":"47221","news_infos":{"title":"test","date":"2014-05-14 17:44:02","shared":"47"},"website":"test.it"},"3":{"id"="55885",name="foo"}}
this example. want know how can skip sec one, suppose sec 1 jsonarray. illustration of i'm doing in java ;
(int = 0; < jobj.length() ; i++) { seek { jsonobject obj = jobj.getjsonobject(i); //suppose every entry in json object , not jsonarray. if (!obj.isnull("titrenews")) { home home = new home(); log.i("infos","yes"); home.setnomc(obj.getstring("titrenews")); home.setphotoar(photonews); home.settext(obj.getstring("textnews")); home.setnbrsick(obj.getstring("sicks")); homelist.add(home); } }catch (jsonexception e) { e.printstacktrace(); } grab (unsupportedencodingexception e) { e.printstacktrace(); } }
to sum problem have json data. composed of jsonobject , jsonarray, , want skip jsonarray entry , avoid
so solutions please !
try approach:
for (object obj : jobj) { if (obj instanceof jsonobject){ //do } else if (obj instanceof jsonarray){ continue;//skip } }
java json
No comments:
Post a Comment